Группа :: Система/Серверы
Пакет: unfs3
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: unfs3-0.9.17-pidfile.patch
diff -Naur unfs3-0.9.17-orig/CREDITS unfs3-0.9.17/CREDITS
--- unfs3-0.9.17-orig/CREDITS 2007-01-04 21:36:00 +0200
+++ unfs3-0.9.17/CREDITS 2007-01-27 11:15:54 +0200
@@ -25,3 +25,5 @@
- Holger Wolf <Holger.Wolf@de.ibm.com>
- Frank v Waveren <fvw@var.cx>
- Matthew Bloch <matthew@bytemark.co.uk>
+- Anton Farygin <rider@altlinux.com>
+- Michael Shigorin <mike@osdn.org.ua>
diff -Naur unfs3-0.9.17-orig/backend_unix.h unfs3-0.9.17/backend_unix.h
--- unfs3-0.9.17-orig/backend_unix.h 2007-01-05 17:08:12 +0200
+++ unfs3-0.9.17/backend_unix.h 2007-01-27 11:15:54 +0200
@@ -68,5 +68,7 @@
#define backend_passwdstruct struct passwd
#define backend_getpwnam getpwnam
#define backend_gen_nonce gen_nonce
+#define backend_flock flock
+#define backend_getpid getpid
#endif
diff -Naur unfs3-0.9.17-orig/backend_win32.h unfs3-0.9.17/backend_win32.h
--- unfs3-0.9.17-orig/backend_win32.h 2007-01-05 17:08:12 +0200
+++ unfs3-0.9.17/backend_win32.h 2007-01-27 11:15:54 +0200
@@ -67,5 +67,7 @@
#define backend_pathconf_case_insensitive TRUE
#define backend_getpwnam(name) NULL
#define backend_gen_nonce win_gen_nonce
+#define backend_flock flock
+#define backend_getpid getpid
#endif
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-27 11:15:54 +0200
@@ -8,6 +8,7 @@
#include "config.h"
+#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <rpc/rpc.h>
@@ -69,6 +70,7 @@
int opt_brute_force = FALSE;
struct in_addr opt_bind_addr;
int opt_readable_executables = FALSE;
+char *opt_pid_file = NULL;
/* Register with portmapper? */
int opt_portmapper = TRUE;
@@ -134,12 +136,60 @@
}
/*
+ * write current pid to a file
+ */
+static void create_pid_file(void)
+{
+ char buf[16];
+ int fd, res, len;
+
+ if (!opt_pid_file) return;
+
+ fd = backend_open_create(opt_pid_file, O_RDWR | O_CREAT | O_TRUNC, 0644);
+ if (fd == -1) {
+ logmsg(LOG_WARNING, "failed to create pid file `%s'", opt_pid_file);
+ return;
+ }
+
+ res = backend_flock(fd, LOCK_EX | LOCK_NB);
+ if (res == -1) {
+ logmsg(LOG_WARNING, "failed to lock pid file `%s'", opt_pid_file);
+ backend_close(fd);
+ return;
+ }
+
+ sprintf(buf, "%i\n", backend_getpid());
+ len = strlen(buf);
+
+ res = backend_pwrite(fd, buf, len, 0);
+ backend_close(fd);
+ if (res != len) {
+ logmsg(LOG_WARNING, "failed to write pid file `%s'", opt_pid_file);
+ }
+}
+
+/*
+ * remove pid file
+ */
+static void remove_pid_file(void)
+{
+ int res;
+
+ if (!opt_pid_file) return;
+
+ res = backend_remove(opt_pid_file);
+ if (res == -1 && errno != ENOENT) {
+ logmsg(LOG_WARNING, "failed to remove pid file `%s'", opt_pid_file);
+ }
+}
+
+/*
* parse command line options
*/
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);
@@ -177,6 +227,7 @@
printf("\t-u use unprivileged port for services\n");
printf("\t-d do not detach from terminal\n");
printf("\t-e <file> file to use instead of /etc/exports\n");
+ printf("\t-i <file> write daemon pid to given file\n");
#ifdef WANT_CLUSTER
printf("\t-c enable cluster extensions\n");
printf("\t-C <path> set path for cluster extensions\n");
@@ -239,6 +290,9 @@
opt_nfs_port = 0;
opt_mount_port = 0;
break;
+ case 'i':
+ opt_pid_file = optarg;
+ break;
case '?':
exit(1);
break;
@@ -288,6 +342,7 @@
if (opt_detach)
closelog();
+ remove_pid_file();
backend_shutdown();
exit(1);
@@ -862,6 +917,9 @@
/* no umask to not screw up create modes */
umask(0);
+
+ /* create pid file if wanted */
+ create_pid_file();
/* initialize internal stuff */
fh_cache_init();
diff -Naur unfs3-0.9.17-orig/unfsd.8 unfs3-0.9.17/unfsd.8
--- unfs3-0.9.17-orig/unfsd.8 2007-01-17 09:15:08 +0200
+++ unfs3-0.9.17/unfsd.8 2007-01-27 11:15:54 +0200
@@ -80,6 +80,12 @@
.IR /etc/exports .
Note that the file needs to be specified using an absolute path.
.TP
+.BI "\-i " "\<file\>"
+Use the given file as pid file. When the daemon starts up, it will
+write its pid (process id) to the given file. Upon exit, the daemon
+will remove the file. Failure to create or remove the pid file is
+not considered fatal and only reported to syslog.
+.TP
.B \-u
Use an unprivileged port for NFS and MOUNT service. Normally,
.B unfsd