Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 193861 Details for
Bug 240973
RFE: Allow debugging to be enabled on the fly
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Updated version of the patch to enable switching log priorities at run-time.
autofs-4.1.3-on-the-fly-debugging.patch (text/plain), 10.15 KB, created by
Jeff Moyer
on 2007-09-12 19:36:15 UTC
(
hide
)
Description:
Updated version of the patch to enable switching log priorities at run-time.
Filename:
MIME Type:
Creator:
Jeff Moyer
Created:
2007-09-12 19:36:15 UTC
Size:
10.15 KB
patch
obsolete
>--- autofs-4.1.3/daemon/automount.c.on-the-fly 2007-09-12 15:13:37.000000000 -0400 >+++ autofs-4.1.3/daemon/automount.c 2007-09-12 15:17:12.000000000 -0400 >@@ -20,6 +20,7 @@ > * > * ----------------------------------------------------------------------- */ > >+#include <ctype.h> > #include <dirent.h> > #include <errno.h> > #include <fcntl.h> >@@ -38,6 +39,8 @@ > #include <sys/stat.h> > #include <sys/time.h> > #include <sys/poll.h> >+#include <sys/socket.h> >+#include <sys/un.h> > #include <linux/auto_fs4.h> > > #include "automount.h" >@@ -1168,18 +1171,200 @@ static int fullread(int fd, void *ptr, s > return len; > } > >+static char *automount_path_to_fifo(const char *path) >+{ >+ char *fifo_name, *p; >+ int name_len = strlen(path) + strlen(AUTOFS_LOGPRI_FIFO) + 1; >+ int ret; >+ >+ fifo_name = malloc(name_len); >+ if (!fifo_name) >+ return NULL; >+ ret = snprintf(fifo_name, name_len, "%s%s", >+ AUTOFS_LOGPRI_FIFO, path); >+ if (ret >= name_len) { >+ warn("fifo path for \"%s\" truncated to \"%s\". This may " >+ "lead to --set-log-priority commands being sent to the " >+ "wrong automount daemon.\n", path, fifo_name); >+ } >+ >+ /* >+ * An automount path can be made up of subdirectories. So, to >+ * create the fifo name, we will just replace instances of '/' with >+ * '-'. >+ */ >+ p = fifo_name + strlen(AUTOFS_LOGPRI_FIFO); >+ while (*p != '\0') { >+ if (*p == '/') >+ *p = '-'; >+ p++; >+ } >+ >+ debug("%s: fifo name %s\n", __FUNCTION__, fifo_name); >+ return fifo_name; >+} >+ >+static void create_logpri_fifo(const char *path) >+{ >+ int ret; >+ int fd; >+ char *fifo_name; >+ >+ fifo_name = automount_path_to_fifo(path); >+ if (!fifo_name) { >+ crit("%s: Failed to allocate memory!\n", __FUNCTION__); >+ exit(1); >+ } >+ >+ ret = unlink(fifo_name); >+ if (ret != 0 && errno != ENOENT) { >+ crit("%s: Failed to unlink FIFO. Is the automount daemon " >+ "already running?\n", __FUNCTION__); >+ exit(1); >+ } >+ >+ ret = mkfifo(fifo_name, S_IRUSR|S_IWUSR); >+ if (ret != 0) { >+ crit("%s: mkfifo for %s returned %d\n", __FUNCTION__, >+ fifo_name, errno); >+ exit(1); >+ } >+ >+ fd = open(fifo_name, O_RDWR|O_NONBLOCK); >+ if (fd < 0) { >+ crit("%s: Failed to open %s, errno %d\n", __FUNCTION__, >+ fifo_name, errno); >+ exit(1); >+ } >+ >+ free(fifo_name); >+ ap.logpri_fifo = fd; >+ return; >+} >+ >+static void handle_fifo_message(int fd) >+{ >+ int len, ret; >+ char buffer[PIPE_BUF]; >+ char *end; >+ long pri; >+ >+ memset(buffer, 0, sizeof(buffer)); >+ ret = read(fd, &buffer, sizeof(buffer)); >+ if (ret < 0) { >+ warn("%s: read on fifo returned error %d\n", >+ __FUNCTION__, errno); >+ return; >+ } >+ >+ if (ret != 2) { >+ debug("%s: expected 2 bytes, received %d.\n", >+ __FUNCTION__, ret); >+ return; >+ } >+ >+ errno = 0; >+ pri = strtol(buffer, &end, 10); >+ if ((pri == LONG_MIN || pri == LONG_MAX) && errno == ERANGE) { >+ debug("%s: strtol reported an %s. Failed to set " >+ "log priority.\n", __FUNCTION__, >+ pri == LONG_MIN ? "underflow" : "overflow"); >+ return; >+ } >+ if ((pri == 0 && errno == EINVAL) || end == buffer) { >+ debug("%s: priority is expected to be an integer in the range" >+ " 0-7 inclusive.\n", __FUNCTION__); >+ return; >+ } >+ >+ if (pri > LOG_DEBUG || pri < LOG_EMERG) { >+ debug("%s: invalid log priority (%ld) received on fifo\n", >+ __FUNCTION__, pri); >+ return; >+ } >+ >+ /* >+ * OK, the message passed all of the sanity checks. The >+ * automounter actually only supports two log priorities. >+ * Everything at warning or above is only logged when >+ * debugging is enabled. >+ */ >+ if (pri >= LOG_WARNING) { >+ do_debug = 1; >+ info("Debug logging enabled.\n"); >+ } else { >+ if (do_verbose || do_debug) >+ crit("Debug logging disabled.\n"); >+ do_verbose = do_debug = 0; >+ } >+} >+ >+static int set_log_priority(const char *path, int priority) >+{ >+ int fd; >+ char *fifo_name; >+ char buf[2]; >+ >+ if (priority > LOG_DEBUG || priority < LOG_EMERG) { >+ fprintf(stderr, "Log priority %d is invalid.\n", priority); >+ fprintf(stderr, "Please spcify a number in the range 0-7.\n"); >+ return -1; >+ } >+ >+ /* >+ * This is an ascii based protocol, so we want the string >+ * representation of the integer log priority. >+ */ >+ snprintf(buf, sizeof(buf), "%d", priority); >+ >+ fifo_name = automount_path_to_fifo(path); >+ if (!fifo_name) { >+ fprintf(stderr, "%s: Failed to allocate memory!\n", >+ __FUNCTION__); >+ return -1; >+ } >+ >+ /* >+ * Specify O_NONBLOCK so that the open will fail if there is no >+ * daemon reading from the other side of the FIFO. >+ */ >+ fd = open(fifo_name, O_WRONLY|O_NONBLOCK); >+ if (fd < 0) { >+ fprintf(stderr, "%s: open of %s failed with %d\n", >+ __FUNCTION__, fifo_name, errno); >+ free(fifo_name); >+ return -1; >+ } >+ >+ if (write(fd, buf, sizeof(buf)) != sizeof(buf)) { >+ fprintf(stderr, "Failed to change logging priority. "); >+ fprintf(stderr, "write to fifo failed with errno %d.\n", >+ errno); >+ close(fd); >+ free(fifo_name); >+ return -1; >+ } >+ close(fd); >+ free(fifo_name); >+ fprintf(stdout, "Successfully set log priority.\n"); >+ >+ return 0; >+} >+ > static int get_pkt(int fd, union autofs_packet_union *pkt) > { > sigset_t old; >- struct pollfd fds[2]; >+ struct pollfd fds[3]; > > fds[0].fd = fd; > fds[0].events = POLLIN; > fds[1].fd = ap.state_pipe[0]; > fds[1].events = POLLIN; >+ fds[2].fd = ap.logpri_fifo; >+ fds[2].events = POLLIN; > > for (;;) { >- if (poll(fds, 2, -1) == -1) { >+ if (poll(fds, 3, -1) == -1) { > if (errno == EINTR) > continue; > syslog(LOG_ERR, "get_pkt: poll failed: %m"); >@@ -1246,6 +1431,11 @@ static int get_pkt(int fd, union autofs_ > > if (fds[0].revents & POLLIN) > return fullread(fd, pkt, sizeof(*pkt)); >+ >+ if (fds[2].revents & POLLIN) { >+ debug("connection pending on control socket."); >+ handle_fifo_message(fds[2].fd); >+ } > } > } > >@@ -2005,11 +2195,47 @@ void init_path_mounted(void) > path_mounted = _PATH_MOUNTED; > } > >+typedef struct _code { >+ char *c_name; >+ int c_val; >+} CODE; >+ >+CODE prioritynames[] = { >+ { "alert", LOG_ALERT }, >+ { "crit", LOG_CRIT }, >+ { "debug", LOG_DEBUG }, >+ { "emerg", LOG_EMERG }, >+ { "err", LOG_ERR }, >+ { "error", LOG_ERR }, /* DEPRECATED */ >+ { "info", LOG_INFO }, >+ { "notice", LOG_NOTICE }, >+ { "panic", LOG_EMERG }, /* DEPRECATED */ >+ { "warn", LOG_WARNING }, /* DEPRECATED */ >+ { "warning", LOG_WARNING }, >+ { NULL, -1 }, >+}; >+ >+static int convert_log_priority(char *priority_name) >+{ >+ CODE *priority_mapping; >+ >+ for (priority_mapping = prioritynames; >+ priority_mapping->c_name != NULL; >+ priority_mapping++) { >+ >+ if (!strcasecmp(priority_name, priority_mapping->c_name)) >+ return priority_mapping->c_val; >+ } >+ >+ return -1; >+} >+ > int main(int argc, char *argv[]) > { > char *path, *map, *mapfmt; > const char **mapargv; > int mapargc, opt; >+ int logpri = -1; > static const struct option long_options[] = { > {"help", 0, 0, 'h'}, > {"pid-file", 1, 0, 'p'}, >@@ -2024,6 +2250,7 @@ int main(int argc, char *argv[]) > {"random-multimount-selection", 0, 0, 'r'}, > {"use-old-ldap-lookup", 0, 0, 'u'}, > {"negative-timeout", 1, 0, 'n'}, >+ {"set-log-priority", 1, 0, 'l'}, > {0, 0, 0, 0} > }; > >@@ -2037,7 +2264,7 @@ int main(int argc, char *argv[]) > ap.negative_timeout = 60; > > opterr = 0; >- while ((opt = getopt_long(argc, argv, "+hp:t:vdVgDrun:", long_options, NULL)) != EOF) { >+ while ((opt = getopt_long(argc, argv, "+hp:t:vdVgDrun:l:", long_options, NULL)) != EOF) { > switch (opt) { > case 'h': > usage(); >@@ -2083,6 +2310,22 @@ int main(int argc, char *argv[]) > case 'n': > ap.negative_timeout = getnumopt(optarg, opt); > break; >+ case 'l': >+ if (isalpha(*optarg)) { >+ logpri = convert_log_priority(optarg); >+ if (logpri < 0) { >+ fprintf(stderr, "Invalid log priority:" >+ " %s\n", optarg); >+ exit(1); >+ } >+ } else if (isdigit(*optarg)) { >+ logpri = getnumopt(optarg, opt); >+ } else { >+ fprintf(stderr, "non-alphanumeric character " >+ "found in log priority. Aborting.\n"); >+ exit(1); >+ } >+ break; > case '?': > case ':': > printf("%s: Ambiguous or unknown options\n", program); >@@ -2099,13 +2342,35 @@ int main(int argc, char *argv[]) > argv += optind; > argc -= optind; > >+ if (logpri >= 0) { >+ int exit_code = 0; >+ int i; >+ >+ /* >+ * The remaining argv elements are the paths for which >+ * log priorities must be changed. >+ */ >+ for (i = 0; i < argc; i++) { >+ if (set_log_priority(argv[i], logpri) < 0) >+ exit_code = 1; >+ } >+ if (argc < 1) { >+ fprintf(stderr, >+ "--set-log-priority requires a path.\n"); >+ exit_code = 1; >+ } >+ exit(exit_code); >+ } >+ > if (argc < 2) { > usage(); > exit(1); > } > >- if (!dumpmap) >+ if (!dumpmap) { > become_daemon(); >+ create_logpri_fifo(argv[0]); >+ } > > init_path_mounted(); > >--- autofs-4.1.3/man/automount.8.on-the-fly 2007-09-12 15:27:23.000000000 -0400 >+++ autofs-4.1.3/man/automount.8 2007-09-12 15:25:56.000000000 -0400 >@@ -46,6 +46,12 @@ until accesssed. The wildcard map is not > .TP > .I "\-V, \-\-version" > Display the version number, then exit. >+.TP >+.I "\-l, \-\-set-log-priority priority path [path,...]" >+Set the daemon log priority to the specified value. Valid values include >+the numbers 0-7, or the strings emerg, alert, crit, err, warning, notice, >+info, or debug. The \fIpath\fP argument corresponds to the automounted >+path name as specified in the master map. > .SH ARGUMENTS > \fBautomount\fP takes at least three arguments. Mandatory arguments > include \fImount-point\fP, \fImap-type\fP and \fImap\fP. Both mandatory >--- autofs-4.1.3/include/automount.h.on-the-fly 2007-09-12 15:13:37.000000000 -0400 >+++ autofs-4.1.3/include/automount.h 2007-09-12 15:13:37.000000000 -0400 >@@ -111,6 +111,7 @@ struct autofs_point { > char *path; /* Mount point name */ > int pipefd; /* File descriptor for pipe */ > int ioctlfd; /* File descriptor for ioctls */ >+ int logpri_fifo; /* FIFO used for changing log levels */ > dev_t dev; /* "Device" number assigned by kernel */ > char *maptype; /* Type of map "file", "NIS", etc */ > unsigned int type; /* Type of map direct or indirect */ >@@ -158,6 +159,8 @@ int is_mounted(const char *path); > #define KEY_MAX_LEN NAME_MAX > #define MAPENT_MAX_LEN 4095 > >+#define AUTOFS_LOGPRI_FIFO "/tmp/autofs.fifo" >+ > #ifdef MODULE_LOOKUP > int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context); > int lookup_ghost(const char *, int, time_t, void *);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 240973
:
161200
| 193861