Skip to content

Commit c527fe7

Browse files
authored
ledmon: change returns and exits for macro (#212)
Commit f08dd2c ("Fix build with Musl libc (#139)") introduced a new way of handling exits. For ledmon statuses to display properly EXIT() macro must be called instead of exit() and return in main. Switch exit() and (main) returns in ledmon to EXIT(). Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
1 parent 1c3185e commit c527fe7

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/ledmon/ledmon.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ static void _add_block(struct block_device *block)
726726
temp->sysfs_path = strdup(block->sysfs_path);
727727
if (!temp->sysfs_path) {
728728
log_error("Memory allocation error!");
729-
exit(1);
729+
EXIT(1);
730730
}
731731
}
732732
} else {
@@ -737,7 +737,7 @@ static void _add_block(struct block_device *block)
737737
ibpi2str_table(temp->ibpi, ibpi_str_ledmon, buf, sizeof(buf)));
738738
if (!list_append(&ledmon_block_list, temp)) {
739739
log_error("Memory allocation error!");
740-
exit(1);
740+
EXIT(1);
741741
}
742742
}
743743
}
@@ -950,47 +950,47 @@ int main(int argc, char *argv[])
950950
lib_rc = led_new(&ctx);
951951
if (lib_rc != LED_STATUS_SUCCESS) {
952952
fprintf(stderr, "Unable to initialize lib LED %u\n", lib_rc);
953-
return lib_rc;
953+
EXIT(lib_rc);
954954
}
955955

956956
openlog(progname, LOG_PID | LOG_PERROR, LOG_DAEMON);
957957

958958
if (atexit(_ledmon_status))
959-
return LEDMON_STATUS_ONEXIT_ERROR;
959+
EXIT(LEDMON_STATUS_ONEXIT_ERROR);
960960

961961
if (_cmdline_parse_non_daemonize(argc, argv) != LEDMON_STATUS_SUCCESS)
962-
return LEDMON_STATUS_CMDLINE_ERROR;
962+
EXIT(LEDMON_STATUS_CMDLINE_ERROR);
963963

964964
if (geteuid() != 0) {
965965
fprintf(stderr, "Only root can run this application.\n");
966-
return LEDMON_STATUS_NOT_A_PRIVILEGED_USER;
966+
EXIT(LEDMON_STATUS_NOT_A_PRIVILEGED_USER);
967967
}
968968

969969
status = _init_ledmon_conf();
970970
if (status != LEDMON_STATUS_SUCCESS)
971-
return status;
971+
EXIT(status);
972972

973973
status = ledmon_read_conf(ledmon_conf_path, &conf);
974974
if (status != LEDMON_STATUS_SUCCESS)
975-
return status;
975+
EXIT(status);
976976

977977
if (_cmdline_parse(argc, argv) != LEDMON_STATUS_SUCCESS)
978-
return LEDMON_STATUS_CMDLINE_ERROR;
978+
EXIT(LEDMON_STATUS_CMDLINE_ERROR);
979979

980980
ledmon_write_shared_conf(&conf);
981981

982982
if (log_open(&conf) != LEDMON_STATUS_SUCCESS)
983-
return LEDMON_STATUS_LOG_FILE_ERROR;
983+
EXIT(LEDMON_STATUS_LOG_FILE_ERROR);
984984

985985
status = load_library_prefs();
986986
if (status != LEDMON_STATUS_SUCCESS)
987-
return status;
987+
EXIT(status);
988988

989989
free(shortopt);
990990
free(longopt);
991991
if (pidfile_check(progname, NULL) == 0) {
992992
log_warning("daemon is running...");
993-
return LEDMON_STATUS_LEDMON_RUNNING;
993+
EXIT(LEDMON_STATUS_LEDMON_RUNNING);
994994
}
995995
if (!foreground) {
996996
pid_t pid = fork();
@@ -1016,7 +1016,7 @@ int main(int argc, char *argv[])
10161016
int t = open("/dev/null", O_RDWR);
10171017
if (t < 0) {
10181018
log_debug("%s: open(/dev/null) failed (errno=%d).", __func__, errno);
1019-
exit(EXIT_FAILURE);
1019+
EXIT(EXIT_FAILURE);
10201020
}
10211021
UNUSED(dup(t));
10221022
UNUSED(dup(t));
@@ -1044,7 +1044,7 @@ int main(int argc, char *argv[])
10441044
timestamp = time(NULL);
10451045
if (led_scan(ctx) != LED_STATUS_SUCCESS) {
10461046
log_error("Error on led_scan\n");
1047-
exit(1);
1047+
EXIT(1);
10481048
}
10491049
_ledmon_execute();
10501050
_ledmon_wait(conf.scan_interval);

0 commit comments

Comments
 (0)