Группа :: Система/Серверы
Пакет: unfs3
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: unfs3-0.9.17-alt-pidfile.patch
diff -Naur unfs3-0.9.17-orig/daemon.c unfs3-0.9.17/daemon.c
--- unfs3-0.9.17-orig/daemon.c 2007-01-17 09:15:08 +0200
+++ unfs3-0.9.17/daemon.c 2007-01-23 17:57:53 +0200
@@ -60,6 +60,7 @@
/* options and default values */
int opt_detach = TRUE;
char *opt_exports = "/etc/exports";
+char *opt_pidfile = "/var/run/unfsd.pid";
int opt_cluster = FALSE;
char *opt_cluster_path = "/";
int opt_tcponly = FALSE;
@@ -139,7 +140,7 @@
static void parse_options(int argc, char **argv)
{
int opt = 0;
- char *optstring = "bcC:de:hl:m:n:prstuw";
+ char *optstring = "bcC:de:hl:m:n:prstuwi:";
while (opt != -1) {
opt = getopt(argc, argv, optstring);
@@ -242,6 +243,9 @@
case '?':
exit(1);
break;
+ case 'i':
+ opt_pidfile = optarg;
+ break;
}
}
}
@@ -290,6 +294,12 @@
backend_shutdown();
+ // killpid
+ fprintf(stderr, "Deleting pidfile %s\n", opt_pidfile); // ok, if fork done this mesage goes to /dev/null
+ if (unlink(opt_pidfile) == -1) {
+ logmsg(LOG_EMERG,"Failed to delete pidfile");
+ }
+
exit(1);
}
@@ -863,6 +873,21 @@
/* no umask to not screw up create modes */
umask(0);
+ // pidfile always created here - by parent if !opt_detach or by child
+ int pid_fd = open(opt_pidfile, O_RDWR | O_CREAT, 0640);
+ if (pid_fd < 0) {
+ fprintf(stderr, "Failed to open pidfile %s: %s!\n", opt_pidfile, strerror(errno));
+ exit(0);
+ }
+ if (lockf(pid_fd, F_TLOCK, 0) < 0) {
+ fprintf(stderr, "Failed to get a lock on pidfile %s: %s!\n", opt_pidfile, strerror(errno));
+ exit(0);
+ }
+ char str[16];
+
+ snprintf(str, sizeof(str), "%d\n", getpid());
+ write(pid_fd, str, strlen(str));
+
/* initialize internal stuff */
fh_cache_init();
fd_cache_init();
diff -Naur unfs3-0.9.17-orig/daemon.h unfs3-0.9.17/daemon.h
--- unfs3-0.9.17-orig/daemon.h 2007-01-17 09:15:08 +0200
+++ unfs3-0.9.17/daemon.h 2007-01-23 17:44:29 +0200
@@ -36,6 +36,7 @@
/* options */
extern int opt_detach;
extern char *opt_exports;
+extern char *opt_pidfile;
extern int opt_cluster;
extern char *opt_cluster_path;
extern int opt_singleuser;