During initialization, print messages for fatal errors

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
This commit is contained in:
Patrick McCarty
2016-04-22 12:39:09 -07:00
parent 8775f5e3d8
commit 6c190b6643
3 changed files with 10 additions and 1 deletions
+2
View File
@@ -57,11 +57,13 @@ int swupd_curl_init(void)
curl_ret = curl_global_init(CURL_GLOBAL_ALL);
if (curl_ret != CURLE_OK) {
printf("Error: failed to initialize CURL environment\n");
return -1;
}
curl = curl_easy_init();
if (curl == NULL) {
printf("Error: failed to initialize CURL session\n");
curl_global_cleanup();
return -1;
}
+3
View File
@@ -170,6 +170,7 @@ int create_required_dirs(void)
string_or_die(&cmd, "mkdir -p %s/%s", state_dir, dirs[i]);
ret = system(cmd);
if (ret) {
printf("Error: failed to create %s/%s\n", state_dir, dirs[i]);
return -1;
}
free(cmd);
@@ -177,6 +178,7 @@ int create_required_dirs(void)
string_or_die(&dir, "%s/%s", state_dir, dirs[i]);
ret = chmod(dir, S_IRWXU);
if (ret) {
printf("Error: failed to set mode for %s/%s\n", state_dir, dirs[i]);
return -1;
}
free(dir);
@@ -185,6 +187,7 @@ int create_required_dirs(void)
// chmod 700
ret = chmod(state_dir, S_IRWXU);
if (ret) {
printf("Error: failed to set mode for state dir (%s)\n", state_dir);
return -1;
}
}
+5 -1
View File
@@ -59,18 +59,22 @@ int p_lockfile(void)
/* open lock file */
lock_fd = open(lockfile, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
free(lockfile);
if (lock_fd < 0) {
printf("Error: failed to open %s: %s\n", lockfile, strerror(errno));
free(lockfile);
return -1;
}
free(lockfile);
/* try to get an advisory region lock for the file */
ret = fcntl(lock_fd, F_SETLK, &fl);
if (ret == -1) {
if ((errno == EAGAIN) || (errno == EACCES)) {
ret = -EAGAIN;
}
printf("Error: cannot acquire lock file. Another swupd process is already running.\n");
close(lock_fd);
return ret;
} else {