Lines 25-31
Link Here
|
25 |
#include <syslog.h> |
25 |
#include <syslog.h> |
26 |
#include <time.h> |
26 |
#include <time.h> |
27 |
#include <unistd.h> |
27 |
#include <unistd.h> |
28 |
|
28 |
#include <errno.h> |
29 |
#if HAVE_RPC_SVC_SOC_H == 1 |
29 |
#if HAVE_RPC_SVC_SOC_H == 1 |
30 |
# include <rpc/svc_soc.h> |
30 |
# include <rpc/svc_soc.h> |
31 |
#endif |
31 |
#endif |
Lines 54-59
Link Here
|
54 |
int opt_expire_writers = FALSE; |
54 |
int opt_expire_writers = FALSE; |
55 |
int opt_detach = TRUE; |
55 |
int opt_detach = TRUE; |
56 |
char *opt_exports = "/etc/exports"; |
56 |
char *opt_exports = "/etc/exports"; |
|
|
57 |
char *opt_pidfile = "/var/run/unfsd.pid"; |
57 |
int opt_cluster = FALSE; |
58 |
int opt_cluster = FALSE; |
58 |
char *opt_cluster_path = "/"; |
59 |
char *opt_cluster_path = "/"; |
59 |
int opt_tcponly = FALSE; |
60 |
int opt_tcponly = FALSE; |
Lines 114-120
Link Here
|
114 |
static void parse_options(int argc, char **argv) |
115 |
static void parse_options(int argc, char **argv) |
115 |
{ |
116 |
{ |
116 |
int opt = 0; |
117 |
int opt = 0; |
117 |
char *optstring = "bcC:de:hl:m:n:pstuw"; |
118 |
char *optstring = "bcC:de:hl:m:n:pstuwi:"; |
118 |
|
119 |
|
119 |
while (opt != -1) { |
120 |
while (opt != -1) { |
120 |
opt = getopt(argc, argv, optstring); |
121 |
opt = getopt(argc, argv, optstring); |
Lines 210-215
Link Here
|
210 |
case '?': |
211 |
case '?': |
211 |
exit(1); |
212 |
exit(1); |
212 |
break; |
213 |
break; |
|
|
214 |
case 'i': |
215 |
opt_pidfile = optarg; |
216 |
break; |
213 |
} |
217 |
} |
214 |
} |
218 |
} |
215 |
} |
219 |
} |
Lines 256-261
Link Here
|
256 |
|
260 |
|
257 |
backend_shutdown(); |
261 |
backend_shutdown(); |
258 |
|
262 |
|
|
|
263 |
// killpid |
264 |
fprintf(stderr, "Deleting pidfile %s\n", opt_pidfile); // ok, if fork done this mesage goes to /dev/null |
265 |
if (unlink(opt_pidfile) == -1) { |
266 |
logmsg(LOG_EMERG,"Failed to delete pidfile"); |
267 |
} |
268 |
|
259 |
exit(1); |
269 |
exit(1); |
260 |
} |
270 |
} |
261 |
|
271 |
|
Lines 770-775
Link Here
|
770 |
/* no umask to not screw up create modes */ |
780 |
/* no umask to not screw up create modes */ |
771 |
umask(0); |
781 |
umask(0); |
772 |
|
782 |
|
|
|
783 |
// pidfile always created here - by parent if !opt_detach or by child |
784 |
int pid_fd = open(opt_pidfile, O_RDWR | O_CREAT, 0640); |
785 |
if (pid_fd < 0) { |
786 |
fprintf(stderr, "Failed to open pidfile %s: %s!\n", opt_pidfile, strerror(errno)); |
787 |
exit(0); |
788 |
} |
789 |
if (lockf(pid_fd, F_TLOCK, 0) < 0) { |
790 |
fprintf(stderr, "Failed to get a lock on pidfile %s: %s!\n", opt_pidfile, strerror(errno)); |
791 |
exit(0); |
792 |
} |
793 |
char str[16]; |
794 |
|
795 |
snprintf(str, sizeof(str), "%d\n", getpid()); |
796 |
write(pid_fd, str, strlen(str)); |
797 |
|
773 |
/* detach from terminal */ |
798 |
/* detach from terminal */ |
774 |
if (opt_detach) { |
799 |
if (opt_detach) { |
775 |
setsid(); |
800 |
setsid(); |