summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2011-06-21 11:23:03 +0200
committerMike Christie <michaelc@cs.wisc.edu>2011-06-26 17:37:42 -0500
commitfcf4e53f577a47b4666052ad024f83eb984a658a (patch)
tree92262f74190103719dbc3573626f2699619d05ea /usr
parente5bd9130d5d35cbdce04f04e156bde82a0641583 (diff)
downloadopen-iscsi-fcf4e53f577a47b4666052ad024f83eb984a658a.tar.gz
iscsid: Implement --no-pid-file
For root on iSCSI scenarios the /var directory might not exist. And we don't need the pid file anyway as the daemon is synchronized via the IPC connection. Signed-off-by: Hannes Reinecke <hare@suse.de>
Diffstat (limited to 'usr')
-rw-r--r--usr/iscsid.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/usr/iscsid.c b/usr/iscsid.c
index 3fa3295..1a37347 100644
--- a/usr/iscsid.c
+++ b/usr/iscsid.c
@@ -69,6 +69,7 @@ static struct option const long_options[] = {
{"debug", required_argument, NULL, 'd'},
{"uid", required_argument, NULL, 'u'},
{"gid", required_argument, NULL, 'g'},
+ {"no-pid-file", no_argument, NULL, 'n'},
{"pid", required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
@@ -90,6 +91,7 @@ Open-iSCSI initiator daemon.\n\
-d, --debug debuglevel print debugging information\n\
-u, --uid=uid run as uid, default is current user\n\
-g, --gid=gid run as gid, default is current user group\n\
+ -n, --no-pid-file do not use a pid file\n\
-p, --pid=pidfile use pid file (default " PID_FILE ").\n\
-h, --help display this help and exit\n\
-v, --version display version and exit\n\
@@ -339,7 +341,7 @@ int main(int argc, char *argv[])
int control_fd;
pid_t pid;
- while ((ch = getopt_long(argc, argv, "c:i:fd:u:g:p:vh", long_options,
+ while ((ch = getopt_long(argc, argv, "c:i:fd:nu:g:p:vh", long_options,
&longindex)) >= 0) {
switch (ch) {
case 'c':
@@ -360,6 +362,9 @@ int main(int argc, char *argv[])
case 'g':
gid = strtoul(optarg, NULL, 10);
break;
+ case 'n':
+ pid_file = NULL;
+ break;
case 'p':
pid_file = optarg;
break;
@@ -415,13 +420,15 @@ int main(int argc, char *argv[])
if (daemonize) {
char buf[64];
- int fd;
-
- fd = open(pid_file, O_WRONLY|O_CREAT, 0644);
- if (fd < 0) {
- log_error("Unable to create pid file");
- log_close(log_pid);
- exit(ISCSI_ERR);
+ int fd = -1;
+
+ if (pid_file) {
+ fd = open(pid_file, O_WRONLY|O_CREAT, 0644);
+ if (fd < 0) {
+ log_error("Unable to create pid file");
+ log_close(log_pid);
+ exit(ISCSI_ERR);
+ }
}
pid = fork();
if (pid < 0) {
@@ -439,15 +446,16 @@ int main(int argc, char *argv[])
}
chdir("/");
- if (lockf(fd, F_TLOCK, 0) < 0) {
- log_error("Unable to lock pid file");
- log_close(log_pid);
- exit(ISCSI_ERR);
+ if (fd > 0) {
+ if (lockf(fd, F_TLOCK, 0) < 0) {
+ log_error("Unable to lock pid file");
+ log_close(log_pid);
+ exit(ISCSI_ERR);
+ }
+ ftruncate(fd, 0);
+ sprintf(buf, "%d\n", getpid());
+ write(fd, buf, strlen(buf));
}
- ftruncate(fd, 0);
- sprintf(buf, "%d\n", getpid());
- write(fd, buf, strlen(buf));
-
daemon_init();
} else {
if ((control_fd = ipc->ctldev_open()) < 0) {