diff options
author | Lee Duncan <lduncan@suse.com> | 2021-01-04 16:33:40 -0800 |
---|---|---|
committer | Lee Duncan <lduncan@suse.com> | 2021-01-04 16:33:40 -0800 |
commit | 8570399b5c6c2a484ff3bf22043c9023a968d058 (patch) | |
tree | f128ba0b45b3b3ff0a37df65300d3165db5693c6 /usr | |
parent | 34e3ffb194f6fa3028c0eb2ff57e7db2d1026771 (diff) | |
download | open-iscsi-8570399b5c6c2a484ff3bf22043c9023a968d058.tar.gz |
iscsid: Do not allow conflicting pid-file options
The daemon allowed both the no-pid-file option and specifying
a PID file to use, and honored which ever option was supplied
last. This commmit ensures non-conflicting options are supplied.
Diffstat (limited to 'usr')
-rw-r--r-- | usr/iscsid.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/usr/iscsid.c b/usr/iscsid.c index 3544870..6b46f8f 100644 --- a/usr/iscsid.c +++ b/usr/iscsid.c @@ -63,7 +63,7 @@ struct iscsi_daemon_config *dconfig = &daemon_config; static char program_name[] = "iscsid"; static pid_t log_pid; static gid_t gid; -static int daemonize = 1; +static bool daemonize = true; static int mgmt_ipc_fd; static int sessions_to_recover = 0; @@ -381,6 +381,8 @@ int main(int argc, char *argv[]) struct sigaction sa_new; int control_fd; pid_t pid; + bool pid_file_specified = false; + bool no_pid_file_specified = false; while ((ch = getopt_long(argc, argv, "c:i:fd:nu:g:p:vh", long_options, &longindex)) >= 0) { @@ -392,7 +394,7 @@ int main(int argc, char *argv[]) initiatorname_file = optarg; break; case 'f': - daemonize = 0; + daemonize = false; break; case 'd': log_level = atoi(optarg); @@ -405,9 +407,11 @@ int main(int argc, char *argv[]) break; case 'n': pid_file = NULL; + no_pid_file_specified = true; break; case 'p': pid_file = optarg; + pid_file_specified = true; break; case 'v': printf("%s version %s\n", program_name, @@ -422,6 +426,17 @@ int main(int argc, char *argv[]) } } + if (pid_file_specified) { + if (no_pid_file_specified) { + fprintf(stderr, "error: Conflicting PID-file options requested\n"); + usage(1); + } + if (!daemonize) { + fprintf(stderr, "error: PID file specified but unused in foreground mode\n"); + usage(1); + } + } + /* initialize logger */ log_pid = log_init(program_name, DEFAULT_AREA_SIZE, daemonize ? log_do_log_daemon : log_do_log_std, NULL); |