aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-11-30 23:46:06 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-11-30 23:46:06 +0000
commit3860b2ebd6ad9c68a087c2addd1f1c592aaeaee9 (patch)
tree8d328b48f99fdd6273525a2d7a0a84fc4feb6b60
parent5be6a200f073cf7e84d501a8b8a7accdf7c5ce02 (diff)
downloadbusybox-w32-3860b2ebd6ad9c68a087c2addd1f1c592aaeaee9.tar.gz
busybox-w32-3860b2ebd6ad9c68a087c2addd1f1c592aaeaee9.tar.bz2
busybox-w32-3860b2ebd6ad9c68a087c2addd1f1c592aaeaee9.zip
Patch from Tito, size optimisation, cleanup noise when in debugging
mode, adds support for MODLOAD keyword in devfsd.conf, provides a cleaned up version of example/devfsd.conf
-rw-r--r--examples/devfsd.conf92
-rw-r--r--miscutils/Config.in7
-rw-r--r--miscutils/devfsd.c334
3 files changed, 196 insertions, 237 deletions
diff --git a/examples/devfsd.conf b/examples/devfsd.conf
index ea7334374..e90e7102b 100644
--- a/examples/devfsd.conf
+++ b/examples/devfsd.conf
@@ -25,11 +25,10 @@ UNREGISTER .* RMNEWCOMPAT
25 25
26# Enable module autoloading. You may comment this out if you don't use 26# Enable module autoloading. You may comment this out if you don't use
27# autoloading 27# autoloading
28# Not supported by busybox 28# Supported by busybox when CONFIG_DEVFSD_MODLOAD is set.
29#LOOKUP .* MODLOAD 29# This actually doesn't work with busybox modutils but needs
30# Maybe one of these works for busybox 30# the real modutils' modprobe
31#LOOKUP .* EXECUTE /sbin/modprobe -k -v -C /etc/modules.devfs * 31LOOKUP .* MODLOAD
32#REGISTER .* EXECUTE /sbin/modprobe -k -v -C /etc/modules.devfs *
33 32
34# Uncomment the following if you want to set the group to "tty" for the 33# Uncomment the following if you want to set the group to "tty" for the
35# pseudo-tty devices. This is necessary so that mesg(1) can later be used to 34# pseudo-tty devices. This is necessary so that mesg(1) can later be used to
@@ -68,7 +67,6 @@ RESTORE /lib/dev-state
68REGISTER ^cdroms/cdrom0$ EXECUTE /bin/ln -sf $devname cdrom 67REGISTER ^cdroms/cdrom0$ EXECUTE /bin/ln -sf $devname cdrom
69UNREGISTER ^cdroms/cdrom0$ EXECUTE /bin/rm -f cdrom 68UNREGISTER ^cdroms/cdrom0$ EXECUTE /bin/rm -f cdrom
70 69
71
72#REGISTER ^v4l/video0$ CFUNCTION GLOBAL mksymlink v4l/video0 video 70#REGISTER ^v4l/video0$ CFUNCTION GLOBAL mksymlink v4l/video0 video
73#UNREGISTER ^v4l/video0$ CFUNCTION GLOBAL unlink video 71#UNREGISTER ^v4l/video0$ CFUNCTION GLOBAL unlink video
74#REGISTER ^radio0$ CFUNCTION GLOBAL mksymlink radio0 radio 72#REGISTER ^radio0$ CFUNCTION GLOBAL mksymlink radio0 radio
@@ -80,18 +78,23 @@ REGISTER ^radio0$ EXECUTE /bin/ln -sf radio0 radio
80UNREGISTER ^radio0$ EXECUTE /bin/rm -f radio 78UNREGISTER ^radio0$ EXECUTE /bin/rm -f radio
81 79
82# ALSA stuff 80# ALSA stuff
83# Not supported by busybox
84#LOOKUP snd MODLOAD ACTION snd 81#LOOKUP snd MODLOAD ACTION snd
85# Maybe this works for busybox
86#LOOKUP snd EXECUTE /sbin/modprobe -k -v -C /etc/modules.devfs snd
87 82
88# Uncomment this to let PAM manage devfs 83# Uncomment this to let PAM manage devfs
84# Not supported by busybox
89#REGISTER .* CFUNCTION /lib/security/pam_console_apply_devfsd.so pam_console_apply_single $devpath 85#REGISTER .* CFUNCTION /lib/security/pam_console_apply_devfsd.so pam_console_apply_single $devpath
90 86
91# Uncomment this to manage USB mouse 87# Uncomment this to manage USB mouse
88# Not supported by busybox
92#REGISTER ^input/mouse0$ CFUNCTION GLOBAL mksymlink $devname usbmouse 89#REGISTER ^input/mouse0$ CFUNCTION GLOBAL mksymlink $devname usbmouse
93#UNREGISTER ^input/mouse0$ CFUNCTION GLOBAL unlink usbmouse 90#UNREGISTER ^input/mouse0$ CFUNCTION GLOBAL unlink usbmouse
94# Busybox 91# Busybox
92#REGISTER ^input/mouse0$ EXECUTE /bin/ln -sf $devname usbmouse
93#UNREGISTER ^input/mouse0$ EXECUTE /bin/rm -f usbmouse
94# Not supported by busybox
95#REGISTER ^input/mice$ CFUNCTION GLOBAL mksymlink $devname usbmouse
96#UNREGISTER ^input/mice$ CFUNCTION GLOBAL unlink usbmouse
97# Busybox
95REGISTER ^input/mice$ EXECUTE /bin/ln -sf $devname usbmouse 98REGISTER ^input/mice$ EXECUTE /bin/ln -sf $devname usbmouse
96UNREGISTER ^input/mice$ EXECUTE /bin/rm -f usbmouse 99UNREGISTER ^input/mice$ EXECUTE /bin/rm -f usbmouse
97 100
@@ -107,75 +110,24 @@ LOOKUP ^(ide/hd/c[0-9]+b[0-9]+t[0-9]+u[0-9]+)p[0-9]+$ EXECUTE /bin/dd if=$mntpn
107LOOKUP ^(hd[a-z])[0-9]+$ EXECUTE /bin/dd if=$mntpnt/\1 of=/dev/null count=1 110LOOKUP ^(hd[a-z])[0-9]+$ EXECUTE /bin/dd if=$mntpnt/\1 of=/dev/null count=1
108# IDE-SCSI NEWCOMPAT /dev/sd/* names 111# IDE-SCSI NEWCOMPAT /dev/sd/* names
109#LOOKUP ^(sd/c[0-9]+b[0-9]+t[0-9]+u[0-9]+)p[0-9]+$ EXECUTE /bin/dd if=$mntpnt/\1 of=/dev/null count=1 112#LOOKUP ^(sd/c[0-9]+b[0-9]+t[0-9]+u[0-9]+)p[0-9]+$ EXECUTE /bin/dd if=$mntpnt/\1 of=/dev/null count=1
110# SCSI OLDCOMPAT /dev/scd? names 113#SCSI OLDCOMPAT /dev/scd? names
111LOOKUP ^(scd+)[0-9]+$ EXECUTE /bin/dd if=$mntpnt/\1 of=/dev/null count=1 114LOOKUP ^(scd+)[0-9]+$ EXECUTE /bin/dd if=$mntpnt/\1 of=/dev/null count=1
112 115
113 116
114REGISTER ^dvb/card[0-9]+/[^/]+$ PERMISSIONS root.video 0660 117REGISTER ^dvb/card[0-9]+/[^/]+$ PERMISSIONS root.video 0660
115# Busybox 118# Not supported by busybox
116#REGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ CFUNCTION GLOBAL mksymlink /dev/$devname ost/\2\1 119#REGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ CFUNCTION GLOBAL mksymlink /dev/$devname ost/\2\1
117#UNREGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ CFUNCTION GLOBAL unlink ost/\2\1 120#UNREGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ CFUNCTION GLOBAL unlink ost/\2\1
121# Busybox
118REGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ EXECUTE /bin/ln -sf /dev/$devname ost/\2\1 122REGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ EXECUTE /bin/ln -sf /dev/$devname ost/\2\1
119UNREGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ EXECUTE /bin/rm -f ost/\2\1 123UNREGISTER ^dvb/card([0-9]+)/([^/0-9]*)[0-9]+$ EXECUTE /bin/rm -f ost/\2\1
120 124
121# Include package-generated files from /etc/devfs/conf.d 125# Include package-generated files from /etc/devfs/conf.d
122# Supported by busybox 126# Supported by busybox
123#OPTIONAL_INCLUDE /etc/devfs/conf.d/dvd.conf 127# INCLUDE /etc/devfs/conf.d/
124#INCLUDE /etc/devfs/conf.d/dvd.conf 128INCLUDE /etc/devfs/busybox/
125#OPTIONAL_INCLUDE /etc/devfs/conf.d/ 129# Busybox: just for testing
126#INCLUDE /etc/devfs/conf.d/ 130#INCLUDE /etc/devfs/nothing/
127 131#INCLUDE /etc/devfs/nothing/nothing
128#/etc/devfs/conf.d/dvd.conf 132#OPTIONAL_INCLUDE /etc/devfs/nothing/
129#REGISTER ^ide/host0/bus1/target1/lun0/cd$ CFUNCTION GLOBAL mksymlink ide/host0/bus1/target1/lun0/cd dvd 133#OPTIONAL_INCLUDE /etc/devfs/nothing/nothing
130#UNREGISTER ^ide/host0/bus1/target1/lun0/cd$ CFUNCTION GLOBAL unlink dvd
131REGISTER ^ide/host0/bus1/target1/lun0/cd$ EXECUTE ln -sf ide/host0/bus1/target1/lun0/cd dvd
132UNREGISTER ^ide/host0/bus1/target1/lun0/cd$ EXECUTE rm -f dvd
133
134#/etc/devfs/conf.d/dynamic.conf
135# dynamic desktop and co
136
137REGISTER .*/part.* EXECUTE /etc/dynamic/scripts/part.script add $devpath
138UNREGISTER .*/part.* EXECUTE /etc/dynamic/scripts/part.script del $devpath
139
140REGISTER v4l/video.* EXECUTE /etc/dynamic/scripts/webcam.script add $devpath
141UNREGISTER v4l/video.* EXECUTE /etc/dynamic/scripts/webcam.script del $devpath
142
143REGISTER usb/scanner.* EXECUTE /etc/dynamic/scripts/scanner.script add $devpath
144UNREGISTER usb/scanner.* EXECUTE /etc/dynamic/scripts/scanner.script del $devpath
145
146REGISTER usb/rio500 EXECUTE /etc/dynamic/scripts/rio500.script add $devpath
147UNREGISTER usb/rio500 EXECUTE /etc/dynamic/scripts/rio500.script del $devpath
148
149REGISTER usb/tts/[13579] EXECUTE /etc/dynamic/scripts/visor.script add $devpath
150UNREGISTER usb/tts/[13579] EXECUTE /etc/dynamic/scripts/visor.script del $devpath
151
152REGISTER (usb/lp.*|printers/.*) EXECUTE /etc/dynamic/scripts/lp.script add $devpath
153UNREGISTER (usb/lp.*|printers/.*) EXECUTE /etc/dynamic/scripts/lp.script del $devpath
154
155#/etc/devfs/conf.d/modem.conf
156#REGISTER ^$ CFUNCTION GLOBAL mksymlink modem
157#UNREGISTER ^$ CFUNCTION GLOBAL unlink modem
158REGISTER ^tts/0$ EXECUTE ln -sf $devname modem
159UNREGISTER ^$ EXECUTE rm -f modem
160
161#/etc/devfs/conf.d/mouse.conf
162#REGISTER ^misc/psaux$ CFUNCTION GLOBAL mksymlink misc/psaux mouse
163#UNREGISTER ^misc/psaux$ CFUNCTION GLOBAL unlink mouse
164REGISTER ^misc/psaux$ EXECUTE ln -sf misc/psaux mouse
165UNREGISTER ^misc/psaux$ EXECUTE rm -f mouse
166
167#/etc/devfs/conf.d/psaux.conf
168#REGISTER ^misc/psaux$ CFUNCTION GLOBAL mksymlink misc/psaux psaux
169#UNREGISTER ^misc/psaux$ CFUNCTION GLOBAL unlink psaux
170REGISTER ^misc/psaux$ EXECUTE ln -sf misc/psaux psaux
171UNREGISTER ^misc/psaux$ EXECUTE rm -f psaux
172
173#/etc/devfs/conf.d/rdvd.conf
174REGISTER ^ide/host0/bus1/target1/lun0/cd$ EXECUTE /etc/dynamic/scripts/rawdevice.script add /dev/ide/host0/bus1/target1/lun0/cd /dev/rdvd
175UNREGISTER ^ide/host0/bus1/target1/lun0/cd$ EXECUTE /etc/dynamic/scripts/rawdevice.script del /dev/rdvd
176
177#/etc/devfs/conf.d/ttyS0.conf
178#REGISTER ^tts/0$ CFUNCTION GLOBAL mksymlink tts/0 ttyS0
179#UNREGISTER ^tts/0$ CFUNCTION GLOBAL unlink ttyS0
180REGISTER ^tts/0$ EXECUTE ln -sf $devname ttyS0
181UNREGISTER ^tts/0$ EXECUTE rm -f ttyS0
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 0afdadb71..4a013cbd5 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -47,6 +47,13 @@ config CONFIG_DEVFSD
47 Provides compatibility with old device names on a devfs systems. 47 Provides compatibility with old device names on a devfs systems.
48 You should set it to true if you have devfs enabled. 48 You should set it to true if you have devfs enabled.
49 49
50config CONFIG_DEVFSD_MODLOAD
51 bool "Adds support for MODLOAD action"
52 default n
53 depends on CONFIG_DEVFSD
54 help
55 This actually doesn't work with busybox modutils but needs the real modutils.
56
50config CONFIG_DEVFSD_VERBOSE 57config CONFIG_DEVFSD_VERBOSE
51 bool "Increases logging to stderr and syslog" 58 bool "Increases logging to stderr and syslog"
52 default n 59 default n
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index e5d550835..9f998e723 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -129,6 +129,8 @@ struct devfsd_notify_struct
129#define BUFFER_SIZE 16384 129#define BUFFER_SIZE 16384
130#define DEVFSD_VERSION "1.3.25" 130#define DEVFSD_VERSION "1.3.25"
131#define CONFIG_FILE "/etc/devfsd.conf" 131#define CONFIG_FILE "/etc/devfsd.conf"
132#define MODPROBE "/sbin/modprobe"
133#define CONFIG_MODULES_DEVFS "/etc/modules.devfs"
132#define MAX_ARGS (6 + 1) 134#define MAX_ARGS (6 + 1)
133#define MAX_SUBEXPR 10 135#define MAX_SUBEXPR 10
134#define STRING_LENGTH 255 136#define STRING_LENGTH 255
@@ -138,10 +140,15 @@ struct devfsd_notify_struct
138#define GID 1 140#define GID 1
139 141
140/* for msg_logger(), do_ioctl(), 142/* for msg_logger(), do_ioctl(),
141 fork_and_execute() and xopendir(). */ 143 fork_and_execute() */
142# define DIE 1 144# define DIE 1
143# define NO_DIE 0 145# define NO_DIE 0
144 146
147/* for dir_operation() */
148#define RESTORE 0
149#define SERVICE 1
150#define READ_CONFIG 2
151
145/* Update only after changing code to reflect new protocol */ 152/* Update only after changing code to reflect new protocol */
146#define DEVFSD_PROTOCOL_REVISION_DAEMON 5 153#define DEVFSD_PROTOCOL_REVISION_DAEMON 5
147 154
@@ -151,11 +158,11 @@ struct devfsd_notify_struct
151#endif 158#endif
152 159
153#define AC_PERMISSIONS 0 160#define AC_PERMISSIONS 0
154#define AC_MODLOAD 1 /* not supported by busybox */ 161#define AC_MODLOAD 1
155#define AC_EXECUTE 2 162#define AC_EXECUTE 2
156#define AC_MFUNCTION 3 /* not supported by busybox */ 163#define AC_MFUNCTION 3 /* not supported by busybox */
157#define AC_CFUNCTION 4 /* not supported by busybox */ 164#define AC_CFUNCTION 4 /* not supported by busybox */
158#define AC_COPY 5 165#define AC_COPY 5
159#define AC_IGNORE 6 166#define AC_IGNORE 6
160#define AC_MKOLDCOMPAT 7 167#define AC_MKOLDCOMPAT 7
161#define AC_MKNEWCOMPAT 8 168#define AC_MKNEWCOMPAT 8
@@ -209,6 +216,8 @@ struct get_variable_info
209 char devpath[STRING_LENGTH]; 216 char devpath[STRING_LENGTH];
210}; 217};
211 218
219static void dir_operation(int , const char * , int, unsigned long* );
220static void service(struct stat statbuf, char *path);
212static int st_expr_expand(char *, unsigned, const char *, const char *(*) (const char *, void *), void *); 221static int st_expr_expand(char *, unsigned, const char *, const char *(*) (const char *, void *), void *);
213static const char *get_old_name(const char *, unsigned, char *, unsigned, unsigned); 222static const char *get_old_name(const char *, unsigned, char *, unsigned, unsigned);
214static int mksymlink (const char *oldpath, const char *newpath); 223static int mksymlink (const char *oldpath, const char *newpath);
@@ -219,16 +228,18 @@ static void service_name (const struct devfsd_notify_struct *);
219static void action_permissions (const struct devfsd_notify_struct *, const struct config_entry_struct *); 228static void action_permissions (const struct devfsd_notify_struct *, const struct config_entry_struct *);
220static void action_execute (const struct devfsd_notify_struct *, const struct config_entry_struct *, 229static void action_execute (const struct devfsd_notify_struct *, const struct config_entry_struct *,
221 const regmatch_t *, unsigned); 230 const regmatch_t *, unsigned);
231#ifdef CONFIG_DEVFSD_MODLOAD
232static void action_modload (const struct devfsd_notify_struct *info, const struct config_entry_struct *entry);
233#endif
222static void action_copy (const struct devfsd_notify_struct *, const struct config_entry_struct *, 234static void action_copy (const struct devfsd_notify_struct *, const struct config_entry_struct *,
223 const regmatch_t *, unsigned); 235 const regmatch_t *, unsigned);
224static void action_compat (const struct devfsd_notify_struct *, unsigned); 236static void action_compat (const struct devfsd_notify_struct *, unsigned);
225static void free_config (void); 237static void free_config (void);
226static void do_restore (const char *, int); 238static void restore(char *spath, struct stat source_stat, int rootlen);
227static int copy_inode (const char *, const struct stat *, mode_t, const char *, const struct stat *); 239static int copy_inode (const char *, const struct stat *, mode_t, const char *, const struct stat *);
228static mode_t get_mode (const char *); 240static mode_t get_mode (const char *);
229static void signal_handler (int); 241static void signal_handler (int);
230static const char *get_variable (const char *, void *); 242static const char *get_variable (const char *, void *);
231static void do_scan_and_service (const char *);
232static int make_dir_tree (const char *); 243static int make_dir_tree (const char *);
233static int expand_expression(char *, unsigned, const char *, const char *(*)(const char *, void *), void *, 244static int expand_expression(char *, unsigned, const char *, const char *(*)(const char *, void *), void *,
234 const char *, const regmatch_t *, unsigned ); 245 const char *, const regmatch_t *, unsigned );
@@ -243,7 +254,6 @@ static char *write_old_sd_name (char *, unsigned, unsigned, char *);
243static void msg_logger(int die, int pri, const char * fmt, ... ); 254static void msg_logger(int die, int pri, const char * fmt, ... );
244static void do_ioctl(int die, int fd, int request, unsigned long event_mask_flag); 255static void do_ioctl(int die, int fd, int request, unsigned long event_mask_flag);
245static void fork_and_execute(int die, char *arg0, char **arg ); 256static void fork_and_execute(int die, char *arg0, char **arg );
246DIR * xopendir(int die, const char * dir_name);
247static int get_uid_gid ( int, const char *); 257static int get_uid_gid ( int, const char *);
248static void safe_memcpy( char * dest, const char * src, int len); 258static void safe_memcpy( char * dest, const char * src, int len);
249 259
@@ -318,7 +328,7 @@ static void msg_logger(int die, int pri, const char * fmt, ... )
318static void do_ioctl(int die, int fd, int request, unsigned long event_mask_flag) 328static void do_ioctl(int die, int fd, int request, unsigned long event_mask_flag)
319{ 329{
320 if (ioctl (fd, request, event_mask_flag) != 0) 330 if (ioctl (fd, request, event_mask_flag) != 0)
321 msg_logger(die, LOG_ERR, "ioctl() failed: %m\n"); 331 msg_logger(die, LOG_ERR, "ioctl(): %m\n");
322} 332}
323 333
324static void fork_and_execute(int die, char *arg0, char **arg ) 334static void fork_and_execute(int die, char *arg0, char **arg )
@@ -345,21 +355,10 @@ static void fork_and_execute(int die, char *arg0, char **arg )
345 if(arg0 != NULL ) 355 if(arg0 != NULL )
346 { 356 {
347 execvp (arg0, arg); 357 execvp (arg0, arg);
348 msg_logger(DIE, LOG_ERR, "execvp() failed: %s: %m\n", arg0); 358 msg_logger(DIE, LOG_ERR, "execvp(): %s: %m\n", arg0);
349 } 359 }
350} 360}
351 361
352
353DIR * xopendir(int die, const char * dir_name)
354{
355 DIR *dp;
356
357 if ( ( dp = opendir (dir_name) ) == NULL )
358 msg_logger( die, LOG_ERR, "opendir() failed: %s: %m\n", dir_name);
359 /* if die == DIE not reached else return NULL */
360 return dp;
361}
362
363static void safe_memcpy( char *dest, const char *src, int len) 362static void safe_memcpy( char *dest, const char *src, int len)
364{ 363{
365 memcpy (dest , src , len ); 364 memcpy (dest , src , len );
@@ -437,7 +436,7 @@ int devfsd_main (int argc, char **argv)
437 umask (0); 436 umask (0);
438 read_config_file (CONFIG_FILE, FALSE, &event_mask); 437 read_config_file (CONFIG_FILE, FALSE, &event_mask);
439 /* Do the scan before forking, so that boot scripts see the finished product */ 438 /* Do the scan before forking, so that boot scripts see the finished product */
440 do_scan_and_service (mount_point); 439 dir_operation(SERVICE,mount_point,0,NULL);
441 if (no_polling) 440 if (no_polling)
442 exit (0); 441 exit (0);
443 if (do_daemon) 442 if (do_daemon)
@@ -457,7 +456,7 @@ int devfsd_main (int argc, char **argv)
457 free_config (); 456 free_config ();
458 read_config_file (CONFIG_FILE, FALSE, &event_mask); 457 read_config_file (CONFIG_FILE, FALSE, &event_mask);
459 if (do_scan) 458 if (do_scan)
460 do_scan_and_service (mount_point); 459 dir_operation(SERVICE,mount_point,0,NULL);
461 } 460 }
462} /* End Function main */ 461} /* End Function main */
463 462
@@ -476,32 +475,17 @@ static void read_config_file (const char *path, int optional, unsigned long *eve
476 struct stat statbuf; 475 struct stat statbuf;
477 FILE *fp; 476 FILE *fp;
478 char buf[STRING_LENGTH]; 477 char buf[STRING_LENGTH];
478 char *line=NULL;
479 479
480#ifdef CONFIG_DEVFSD_DEBUG 480#ifdef CONFIG_DEVFSD_DEBUG
481 msg_logger( NO_DIE, LOG_INFO, "read_config_file()\n"); 481 msg_logger( NO_DIE, LOG_INFO, "read_config_file()\n");
482#endif 482#endif
483
484 if (stat (path, &statbuf) != 0 || statbuf.st_size == 0 ) 483 if (stat (path, &statbuf) != 0 || statbuf.st_size == 0 )
485 msg_logger((optional == 0 )? DIE : NO_DIE, LOG_ERR, " %s: %m\n", path); 484 goto read_config_file_err;
486 485
487 if ( S_ISDIR (statbuf.st_mode) ) 486 if ( S_ISDIR (statbuf.st_mode) )
488 { 487 {
489 488 dir_operation(READ_CONFIG, path, 0, event_mask);
490 DIR *dp;
491 struct dirent *de;
492
493 dp = xopendir(DIE, path);
494
495 while ( ( de = readdir (dp) ) != NULL )
496 {
497 char fname[STRING_LENGTH];
498
499 if (de->d_name[0] == '.')
500 continue;
501 snprintf (fname, STRING_LENGTH, "%s/%s", path, de->d_name);
502 read_config_file (fname, optional, event_mask);
503 }
504 closedir (dp);
505 return; 489 return;
506 } 490 }
507 491
@@ -509,9 +493,13 @@ static void read_config_file (const char *path, int optional, unsigned long *eve
509 { 493 {
510 while (fgets (buf, STRING_LENGTH, fp) != NULL) 494 while (fgets (buf, STRING_LENGTH, fp) != NULL)
511 { 495 {
512 char *line; 496 /* GETS(3) Linux Programmer's Manual
513 497 fgets() reads in at most one less than size characters from stream and
514 buf[strlen (buf) - 1] = '\0'; 498 stores them into the buffer pointed to by s. Reading stops after an
499 EOF or a newline. If a newline is read, it is stored into the buffer.
500 A '\0' is stored after the last character in the buffer.
501 */
502 /*buf[strlen (buf) - 1] = '\0';*/
515 /* Skip whitespace */ 503 /* Skip whitespace */
516 for (line = buf; isspace (*line); ++line) 504 for (line = buf; isspace (*line); ++line)
517 /*VOID*/; 505 /*VOID*/;
@@ -520,12 +508,13 @@ static void read_config_file (const char *path, int optional, unsigned long *eve
520 process_config_line (line, event_mask); 508 process_config_line (line, event_mask);
521 } 509 }
522 fclose (fp); 510 fclose (fp);
511 errno=0;
512 }
513read_config_file_err:
523#ifdef CONFIG_DEVFSD_VERBOSE 514#ifdef CONFIG_DEVFSD_VERBOSE
524 msg_logger( NO_DIE, LOG_INFO, "read config file: %s\n", path); 515 msg_logger(((optional == 0 ) && (errno == ENOENT))? DIE : NO_DIE, LOG_ERR, "read config file: %s: %m\n", path);
525#endif 516#endif
526 return; 517 return;
527 }
528 msg_logger(( (optional == 0) && (errno == ENOENT) )? DIE : NO_DIE, LOG_ERR, " %s: %m\n", path);
529} /* End Function read_config_file */ 518} /* End Function read_config_file */
530 519
531static void process_config_line (const char *line, unsigned long *event_mask) 520static void process_config_line (const char *line, unsigned long *event_mask)
@@ -541,6 +530,8 @@ static void process_config_line (const char *line, unsigned long *event_mask)
541 char when[STRING_LENGTH], what[STRING_LENGTH]; 530 char when[STRING_LENGTH], what[STRING_LENGTH];
542 char name[STRING_LENGTH]; 531 char name[STRING_LENGTH];
543 char * msg=""; 532 char * msg="";
533 char *ptr;
534
544#ifdef CONFIG_DEVFSD_DEBUG 535#ifdef CONFIG_DEVFSD_DEBUG
545 msg_logger( NO_DIE, LOG_INFO, "process_config_line()\n"); 536 msg_logger( NO_DIE, LOG_INFO, "process_config_line()\n");
546#endif 537#endif
@@ -562,12 +553,15 @@ static void process_config_line (const char *line, unsigned long *event_mask)
562 (strcasecmp (when, "OPTIONAL_INCLUDE") == 0) ) 553 (strcasecmp (when, "OPTIONAL_INCLUDE") == 0) )
563 { 554 {
564 st_expr_expand (name, STRING_LENGTH, name, get_variable, NULL ); 555 st_expr_expand (name, STRING_LENGTH, name, get_variable, NULL );
556#ifdef CONFIG_DEVFSD_VERBOSE
557 msg_logger( NO_DIE, LOG_INFO, "%sinclude: %s\n",(toupper (when[0]) == 'I') ? "": "optional_", name);
558#endif
565 read_config_file (name, (toupper (when[0]) == 'I') ? FALSE : TRUE, event_mask); 559 read_config_file (name, (toupper (when[0]) == 'I') ? FALSE : TRUE, event_mask);
566 return; 560 return;
567 } 561 }
568 if (strcasecmp (when, "RESTORE") == 0) 562 if (strcasecmp (when, "RESTORE") == 0)
569 { 563 {
570 do_restore ( name, strlen (name) ); 564 dir_operation(RESTORE,name, strlen (name),NULL);
571 return; 565 return;
572 } 566 }
573 if (num_args < 3) 567 if (num_args < 3)
@@ -591,8 +585,6 @@ static void process_config_line (const char *line, unsigned long *event_mask)
591 585
592 if (strcasecmp (what, "PERMISSIONS") == 0) 586 if (strcasecmp (what, "PERMISSIONS") == 0)
593 { 587 {
594 char *ptr;
595
596 new->action.what = AC_PERMISSIONS; 588 new->action.what = AC_PERMISSIONS;
597 /* Get user and group */ 589 /* Get user and group */
598 if ( ( ptr = strchr (p[0], '.') ) == NULL ) 590 if ( ( ptr = strchr (p[0], '.') ) == NULL )
@@ -607,6 +599,14 @@ static void process_config_line (const char *line, unsigned long *event_mask)
607 /* Get mode */ 599 /* Get mode */
608 new->u.permissions.mode = get_mode (p[1]); 600 new->u.permissions.mode = get_mode (p[1]);
609 } 601 }
602#ifdef CONFIG_DEVFSD_MODLOAD
603 else if (strcasecmp (what, "MODLOAD") == 0)
604 /*This action will pass "/dev/$devname" (i.e. "/dev/" prefixed to
605 the device name) to the module loading facility. In addition,
606 the /etc/modules.devfs configuration file is used.*/
607
608 new->action.what = AC_MODLOAD;
609#endif
610 else if (strcasecmp (what, "EXECUTE") == 0) 610 else if (strcasecmp (what, "EXECUTE") == 0)
611 { 611 {
612 new->action.what = AC_EXECUTE; 612 new->action.what = AC_EXECUTE;
@@ -673,11 +673,6 @@ static int do_servicing (int fd, unsigned long event_mask)
673#endif 673#endif
674 /* Tell devfs what events we care about */ 674 /* Tell devfs what events we care about */
675 tmp_event_mask = event_mask; 675 tmp_event_mask = event_mask;
676 /* May need to trap inode creates to watch for syslogd(8) starting */
677 /*if (!syslog_is_open && !no_syslog)
678 {
679 tmp_event_mask |= 1 << DEVFSD_NOTIFY_CREATE; *//*FIXME I'm not sure if this line is needed. TITO */
680 /*}*/
681 do_ioctl(DIE, fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); 676 do_ioctl(DIE, fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask);
682 while (!caught_signal) 677 while (!caught_signal)
683 { 678 {
@@ -689,14 +684,6 @@ static int do_servicing (int fd, unsigned long event_mask)
689 continue; /* Yes, the order is important */ 684 continue; /* Yes, the order is important */
690 if (bytes < 1) 685 if (bytes < 1)
691 break; 686 break;
692 /* Special trap for "/dev/log" creation */
693 /* Open syslog, now that "/dev/log" exists */
694 /*if (!syslog_is_open && !no_syslog &&
695 (info.type == DEVFSD_NOTIFY_CREATE) &&(strcmp (info.devname, "log") == 0) )
696 {
697 do_open_syslog ();
698 do_ioctl(DIE, fd, DEVFSDIOC_SET_EVENT_MASK, event_mask);*/ /*FIXME I'm not sure if this line is needed. TITO */
699 /*}*/
700 service_name (&info); 687 service_name (&info);
701 } 688 }
702 if (caught_signal) 689 if (caught_signal)
@@ -752,6 +739,14 @@ static void service_name (const struct devfsd_notify_struct *info)
752#endif 739#endif
753 action_permissions (info, entry); 740 action_permissions (info, entry);
754 break; 741 break;
742#ifdef CONFIG_DEVFSD_MODLOAD
743 case AC_MODLOAD:
744 #ifdef CONFIG_DEVFSD_DEBUG
745 msg_logger( NO_DIE, LOG_INFO, "AC_MODLOAD\n");
746 #endif
747 action_modload (info, entry);
748 break;
749#endif
755 case AC_EXECUTE: 750 case AC_EXECUTE:
756#ifdef CONFIG_DEVFSD_DEBUG 751#ifdef CONFIG_DEVFSD_DEBUG
757 msg_logger( NO_DIE, LOG_INFO, "AC_EXECUTE\n"); 752 msg_logger( NO_DIE, LOG_INFO, "AC_EXECUTE\n");
@@ -805,13 +800,39 @@ static void action_permissions (const struct devfsd_notify_struct *info,
805 chown (info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0) 800 chown (info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0)
806 { 801 {
807#ifdef CONFIG_DEVFSD_VERBOSE 802#ifdef CONFIG_DEVFSD_VERBOSE
808 msg_logger( NO_DIE, LOG_ERR, "chmod() or chown() error for: %s: %m\n",info->devname); 803 msg_logger( NO_DIE, LOG_ERR, "chmod() or chown(): %s: %m\n",info->devname);
809#endif 804#endif
810 return; 805 return;
811 } 806 }
812 807
813} /* End Function action_permissions */ 808} /* End Function action_permissions */
814 809
810#ifdef CONFIG_DEVFSD_MODLOAD
811static void action_modload (const struct devfsd_notify_struct *info,
812 const struct config_entry_struct *entry)
813/* [SUMMARY] Load a module.
814 <info> The devfs change.
815 <entry> The config file entry.
816 [RETURNS] Nothing.
817*/
818{
819 char *argv[6];
820 char device[STRING_LENGTH];
821
822 argv[0] = MODPROBE;
823 argv[1] = "-k";
824 argv[2] = "-C";
825 argv[3] = CONFIG_MODULES_DEVFS;
826 argv[4] = device;
827 argv[5] = NULL;
828 #ifdef CONFIG_DEVFSD_DEBUG
829 msg_logger( NO_DIE, LOG_INFO, "action_modload()\n");
830 #endif
831 snprintf (device, sizeof (device), "/dev/%s", info->devname);
832 fork_and_execute(DIE, argv[0], argv);
833} /* End Function action_modload */
834#endif
835
815static void action_execute (const struct devfsd_notify_struct *info, 836static void action_execute (const struct devfsd_notify_struct *info,
816 const struct config_entry_struct *entry, 837 const struct config_entry_struct *entry,
817 const regmatch_t *regexpr, unsigned int numexpr) 838 const regmatch_t *regexpr, unsigned int numexpr)
@@ -903,8 +924,7 @@ static void action_copy (const struct devfsd_notify_struct *info,
903 regexpr, numexpr); 924 regexpr, numexpr);
904 925
905 if ( !make_dir_tree (destination) || lstat (source, &source_stat) != 0) 926 if ( !make_dir_tree (destination) || lstat (source, &source_stat) != 0)
906 goto action_copy_error; 927 return;
907
908 lstat (destination, &dest_stat); 928 lstat (destination, &dest_stat);
909 new_mode = source_stat.st_mode & ~S_ISVTX; 929 new_mode = source_stat.st_mode & ~S_ISVTX;
910 if (info->type == DEVFSD_NOTIFY_CREATE) 930 if (info->type == DEVFSD_NOTIFY_CREATE)
@@ -913,13 +933,11 @@ static void action_copy (const struct devfsd_notify_struct *info,
913 new_mode |= S_ISVTX; 933 new_mode |= S_ISVTX;
914#ifdef CONFIG_DEVFSD_VERBOSE 934#ifdef CONFIG_DEVFSD_VERBOSE
915 if ( !copy_inode (destination, &dest_stat, new_mode, source, &source_stat) ) 935 if ( !copy_inode (destination, &dest_stat, new_mode, source, &source_stat) )
916action_copy_error: 936 msg_logger( NO_DIE, LOG_ERR, "copy_inode(): %s to %s: %m\n", source, destination);
917 msg_logger( NO_DIE, LOG_ERR, "error copying: %s to %s: %m\n", source, destination);
918#else 937#else
919 copy_inode (destination, &dest_stat, new_mode, source,&source_stat); 938 copy_inode (destination, &dest_stat, new_mode, source, &source_stat);
920action_copy_error:
921 return;
922#endif 939#endif
940 return;
923} /* End Function action_copy */ 941} /* End Function action_copy */
924 942
925static void action_compat (const struct devfsd_notify_struct *info, 943static void action_compat (const struct devfsd_notify_struct *info,
@@ -1041,53 +1059,26 @@ static void action_compat (const struct devfsd_notify_struct *info,
1041 } 1059 }
1042} /* End Function action_compat */ 1060} /* End Function action_compat */
1043 1061
1044static void do_restore (const char *dir_name, int rootlen) 1062static void restore(char *spath, struct stat source_stat, int rootlen)
1045/* [SUMMARY] Restore state from a directory.
1046 <dir_name> The directory containing the backing store.
1047 <rootlen> The length of the root of the state directory hierarchy.
1048 [RETURNS] Nothing.
1049*/
1050{ 1063{
1051 DIR *dp; 1064 char dpath[STRING_LENGTH];
1052 struct dirent *de; 1065 struct stat dest_stat;
1053 1066
1054#ifdef CONFIG_DEVFSD_DEBUG 1067#ifdef CONFIG_DEVFSD_DEBUG
1055 msg_logger( NO_DIE, LOG_INFO, "do_restore()\n"); 1068 msg_logger( NO_DIE, LOG_INFO, "restore()\n");
1056#endif 1069#endif
1057 1070
1058 if( (dp = xopendir(NO_DIE, dir_name))== NULL) 1071 dest_stat.st_mode = 0;
1059 return; 1072 snprintf (dpath, sizeof dpath, "%s%s", mount_point, spath + rootlen);
1060 1073 lstat (dpath, &dest_stat);
1061 while ( (de = readdir (dp) ) != NULL )
1062 {
1063 char spath[STRING_LENGTH], dpath[STRING_LENGTH];
1064
1065 struct stat source_stat, dest_stat;
1066 dest_stat.st_mode = 0;
1067
1068 if ( (strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0) )
1069 continue;
1070
1071 snprintf (spath, sizeof spath, "%s/%s", dir_name, de->d_name);
1072 1074
1073 if (lstat (spath, &source_stat) != 0) 1075 if ( S_ISLNK (source_stat.st_mode) || (source_stat.st_mode & S_ISVTX) )
1074 { 1076 copy_inode (dpath, &dest_stat, (source_stat.st_mode & ~S_ISVTX) , spath, &source_stat);
1075#ifdef CONFIG_DEVFSD_VERBOSE
1076 msg_logger( NO_DIE, LOG_ERR, "%s: %m\n", spath);
1077#endif
1078 continue;
1079 }
1080 snprintf (dpath, sizeof dpath, "%s%s", mount_point, spath + rootlen);
1081 lstat (dpath, &dest_stat);
1082 1077
1083 if ( S_ISLNK (source_stat.st_mode) || (source_stat.st_mode & S_ISVTX) ) 1078 if ( S_ISDIR (source_stat.st_mode) )
1084 copy_inode (dpath, &dest_stat, (source_stat.st_mode & ~S_ISVTX) , spath, &source_stat); 1079 dir_operation(RESTORE, spath, rootlen,NULL);
1080}
1085 1081
1086 if ( S_ISDIR (source_stat.st_mode) )
1087 do_restore (spath, rootlen);
1088 }
1089 closedir (dp);
1090} /* End Function do_restore */
1091 1082
1092static int copy_inode (const char *destpath, const struct stat *dest_stat, 1083static int copy_inode (const char *destpath, const struct stat *dest_stat,
1093 mode_t new_mode, 1084 mode_t new_mode,
@@ -1148,9 +1139,7 @@ static int copy_inode (const char *destpath, const struct stat *dest_stat,
1148 close (fd); 1139 close (fd);
1149 if (val != 0 || chmod (destpath, new_mode & ~S_IFMT) != 0) 1140 if (val != 0 || chmod (destpath, new_mode & ~S_IFMT) != 0)
1150 break; 1141 break;
1151 if (chown (destpath, source_stat->st_uid, source_stat->st_gid) == 0) 1142 goto do_chown;
1152 return (TRUE);
1153 break;
1154 case S_IFLNK: 1143 case S_IFLNK:
1155 if ( ( val = readlink (sourcepath, symlink_val, STRING_LENGTH - 1) ) < 0 ) 1144 if ( ( val = readlink (sourcepath, symlink_val, STRING_LENGTH - 1) ) < 0 )
1156 break; 1145 break;
@@ -1164,23 +1153,19 @@ static int copy_inode (const char *destpath, const struct stat *dest_stat,
1164 close (fd); 1153 close (fd);
1165 if (chmod (destpath, new_mode & ~S_IFMT) != 0) 1154 if (chmod (destpath, new_mode & ~S_IFMT) != 0)
1166 break; 1155 break;
1167 if (chown (destpath, source_stat->st_uid, source_stat->st_gid) == 0) 1156 goto do_chown;
1168 return (TRUE);
1169 break;
1170 case S_IFBLK: 1157 case S_IFBLK:
1171 case S_IFCHR: 1158 case S_IFCHR:
1172 case S_IFIFO: 1159 case S_IFIFO:
1173 if (mknod (destpath, new_mode, source_stat->st_rdev) != 0) 1160 if (mknod (destpath, new_mode, source_stat->st_rdev) != 0)
1174 break; 1161 break;
1175 if (chown (destpath, source_stat->st_uid, source_stat->st_gid) == 0) 1162 goto do_chown;
1176 return (TRUE);
1177 break;
1178 case S_IFDIR: 1163 case S_IFDIR:
1179 if (mkdir (destpath, new_mode & ~S_IFMT) != 0) 1164 if (mkdir (destpath, new_mode & ~S_IFMT) != 0)
1180 break; 1165 break;
1166do_chown:
1181 if (chown (destpath, source_stat->st_uid, source_stat->st_gid) == 0) 1167 if (chown (destpath, source_stat->st_uid, source_stat->st_gid) == 0)
1182 return (TRUE); 1168 return (TRUE);
1183 return (TRUE);
1184 /*break;*/ 1169 /*break;*/
1185 } 1170 }
1186 return (FALSE); 1171 return (FALSE);
@@ -1228,15 +1213,14 @@ static int get_uid_gid (int flag, const char *string)
1228{ 1213{
1229 struct passwd *pw_ent; 1214 struct passwd *pw_ent;
1230 struct group *grp_ent; 1215 struct group *grp_ent;
1231 char * msg_a="user"; 1216 char * msg="user";
1232 char * msg_b="U";
1233 1217
1234#ifdef CONFIG_DEVFSD_DEBUG 1218#ifdef CONFIG_DEVFSD_DEBUG
1235 msg_logger( NO_DIE, LOG_INFO, "get_uid_gid()\n"); 1219 msg_logger( NO_DIE, LOG_INFO, "get_uid_gid()\n");
1236 1220
1237 1221
1238 if(flag != UID && flag != GID ) 1222 if(flag != UID && flag != GID )
1239 msg_logger( DIE, LOG_ERR,"flag != UID && flag != GID\n"); 1223 msg_logger( DIE, LOG_ERR,"get_uid_gid(): flag != UID && flag != GID\n");
1240#endif 1224#endif
1241 1225
1242 if ( isdigit (string[0]) || ( (string[0] == '-') && isdigit (string[1]) ) ) 1226 if ( isdigit (string[0]) || ( (string[0] == '-') && isdigit (string[1]) ) )
@@ -1248,12 +1232,9 @@ static int get_uid_gid (int flag, const char *string)
1248 if ( flag == GID && ( grp_ent = getgrnam (string) ) != NULL ) 1232 if ( flag == GID && ( grp_ent = getgrnam (string) ) != NULL )
1249 return (grp_ent->gr_gid); 1233 return (grp_ent->gr_gid);
1250 else 1234 else
1251 { 1235 msg="group";
1252 msg_a="group";
1253 msg_b="G";
1254 }
1255 1236
1256 msg_logger( NO_DIE, LOG_ERR,"unknown %s: %s, defaulting to %cID=0\n", msg_a, string, msg_b); 1237 msg_logger( NO_DIE, LOG_ERR,"unknown %s: %s, defaulting to %cID=0\n", msg, string, msg[0] - 32);
1257 return (0); 1238 return (0);
1258}/* End Function get_uid_gid */ 1239}/* End Function get_uid_gid */
1259 1240
@@ -1264,7 +1245,7 @@ static mode_t get_mode (const char *string)
1264*/ 1245*/
1265{ 1246{
1266 mode_t mode; 1247 mode_t mode;
1267 1248 int i;
1268#ifdef CONFIG_DEVFSD_DEBUG 1249#ifdef CONFIG_DEVFSD_DEBUG
1269 msg_logger( NO_DIE, LOG_INFO, "get_mode()\n"); 1250 msg_logger( NO_DIE, LOG_INFO, "get_mode()\n");
1270#endif 1251#endif
@@ -1274,15 +1255,14 @@ static mode_t get_mode (const char *string)
1274 if (strlen (string) != 9) 1255 if (strlen (string) != 9)
1275 msg_logger( DIE, LOG_ERR, "bad mode: %s\n", string); 1256 msg_logger( DIE, LOG_ERR, "bad mode: %s\n", string);
1276 mode = 0; 1257 mode = 0;
1277 if (string[0] == 'r') mode |= S_IRUSR; 1258 i= S_IRUSR;
1278 if (string[1] == 'w') mode |= S_IWUSR; 1259 while(i>0)
1279 if (string[2] == 'x') mode |= S_IXUSR; 1260 {
1280 if (string[3] == 'r') mode |= S_IRGRP; 1261 if(string[0]=='r'||string[0]=='w'||string[0]=='x')
1281 if (string[4] == 'w') mode |= S_IWGRP; 1262 mode+=i;
1282 if (string[5] == 'x') mode |= S_IXGRP; 1263 i=i/2;
1283 if (string[6] == 'r') mode |= S_IROTH; 1264 string++;
1284 if (string[7] == 'w') mode |= S_IWOTH; 1265 }
1285 if (string[8] == 'x') mode |= S_IXOTH;
1286 return (mode); 1266 return (mode);
1287} /* End Function get_mode */ 1267} /* End Function get_mode */
1288 1268
@@ -1341,10 +1321,34 @@ static const char *get_variable (const char *variable, void *info)
1341 return (NULL); 1321 return (NULL);
1342} /* End Function get_variable */ 1322} /* End Function get_variable */
1343 1323
1344static void do_scan_and_service (const char *dir_name) 1324static void service(struct stat statbuf, char *path)
1325{
1326 struct devfsd_notify_struct info;
1327
1328#ifdef CONFIG_DEVFSD_DEBUG
1329 msg_logger( NO_DIE, LOG_INFO, "service()\n");
1330#endif
1331
1332 memset (&info, 0, sizeof info);
1333 info.type = DEVFSD_NOTIFY_REGISTERED;
1334 info.mode = statbuf.st_mode;
1335 info.major = major (statbuf.st_rdev);
1336 info.minor = minor (statbuf.st_rdev);
1337 info.uid = statbuf.st_uid;
1338 info.gid = statbuf.st_gid;
1339 snprintf (info.devname, sizeof (info.devname), "%s", path + strlen (mount_point) + 1);
1340 info.namelen = strlen (info.devname);
1341 service_name (&info);
1342 if ( S_ISDIR (statbuf.st_mode) )
1343 dir_operation(SERVICE,path,0,NULL);
1344}
1345
1346static void dir_operation(int type, const char * dir_name, int var, unsigned long *event_mask)
1345/* [SUMMARY] Scan a directory tree and generate register events on leaf nodes. 1347/* [SUMMARY] Scan a directory tree and generate register events on leaf nodes.
1346 <dp> The directory pointer. This is closed upon completion. 1348 <flag> To choose which function to perform
1349 <dp> The directory pointer. This is closed upon completion.
1347 <dir_name> The name of the directory. 1350 <dir_name> The name of the directory.
1351 <rootlen> string length parameter.
1348 [RETURNS] Nothing. 1352 [RETURNS] Nothing.
1349*/ 1353*/
1350{ 1354{
@@ -1353,20 +1357,24 @@ static void do_scan_and_service (const char *dir_name)
1353 struct dirent *de; 1357 struct dirent *de;
1354 char path[STRING_LENGTH]; 1358 char path[STRING_LENGTH];
1355 1359
1360
1356#ifdef CONFIG_DEVFSD_DEBUG 1361#ifdef CONFIG_DEVFSD_DEBUG
1357 msg_logger( NO_DIE, LOG_INFO, "do_scan_and_service ()\n"); 1362 msg_logger( NO_DIE, LOG_INFO, "dir_operation()\n");
1358#endif 1363#endif
1359 1364
1360 if((dp = xopendir(NO_DIE, dir_name))==NULL) 1365 if((dp = opendir( dir_name))==NULL)
1366 {
1367 msg_logger( NO_DIE, LOG_ERR, "opendir(): %s: %m\n", dir_name);
1361 return; 1368 return;
1369 }
1362 1370
1363 while ( (de = readdir (dp) ) != NULL ) 1371 while ( (de = readdir (dp) ) != NULL )
1364 { 1372 {
1365 struct devfsd_notify_struct info;
1366 1373
1367 if ( (strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0) ) 1374 if ( (strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0) )
1368 continue; 1375 continue;
1369 snprintf (path, sizeof (path), "%s/%s", dir_name, de->d_name); 1376 snprintf (path, sizeof (path), "%s%s%s", dir_name,(last_char_is(dir_name,'/')==NULL)?"/":"", de->d_name);
1377
1370 if (lstat (path, &statbuf) != 0) 1378 if (lstat (path, &statbuf) != 0)
1371 { 1379 {
1372#ifdef CONFIG_DEVFSD_VERBOSE 1380#ifdef CONFIG_DEVFSD_VERBOSE
@@ -1374,18 +1382,18 @@ static void do_scan_and_service (const char *dir_name)
1374#endif 1382#endif
1375 continue; 1383 continue;
1376 } 1384 }
1377 memset (&info, 0, sizeof info); 1385 switch(type)
1378 info.type = DEVFSD_NOTIFY_REGISTERED; 1386 {
1379 info.mode = statbuf.st_mode; 1387 case SERVICE:
1380 info.major = major (statbuf.st_rdev); 1388 service(statbuf,path);
1381 info.minor = minor (statbuf.st_rdev); 1389 break;
1382 info.uid = statbuf.st_uid; 1390 case RESTORE:
1383 info.gid = statbuf.st_gid; 1391 restore(path, statbuf, var);
1384 snprintf (info.devname, sizeof (info.devname), "%s", path + strlen (mount_point) + 1); 1392 break;
1385 info.namelen = strlen (info.devname); 1393 case READ_CONFIG:
1386 service_name (&info); 1394 read_config_file (path, var, event_mask);
1387 if ( S_ISDIR (statbuf.st_mode) ) 1395 break;
1388 do_scan_and_service (path); 1396 }
1389 } 1397 }
1390 closedir (dp); 1398 closedir (dp);
1391} /* End Function do_scan_and_service */ 1399} /* End Function do_scan_and_service */
@@ -1408,17 +1416,10 @@ static int mksymlink (const char *oldpath, const char *newpath)
1408 if (symlink (oldpath, newpath) != 0) 1416 if (symlink (oldpath, newpath) != 0)
1409 { 1417 {
1410#ifdef CONFIG_DEVFSD_VERBOSE 1418#ifdef CONFIG_DEVFSD_VERBOSE
1411 if (errno == EEXIST) 1419 msg_logger( NO_DIE, LOG_ERR, "symlink(): %s to %s: %m\n", oldpath, newpath);
1412 msg_logger( NO_DIE, LOG_INFO, "symlink(): %s: already exists\n", newpath); 1420#endif
1413 else
1414 {
1415 msg_logger( NO_DIE, LOG_ERR, "symlink(): %s: %m\n", newpath);
1416 return (-1);
1417 }
1418#else
1419 if (errno != EEXIST) 1421 if (errno != EEXIST)
1420 return (-1); 1422 return (-1);
1421#endif
1422 } 1423 }
1423 return (0); 1424 return (0);
1424} /* End Function mksymlink */ 1425} /* End Function mksymlink */
@@ -1701,7 +1702,6 @@ static char get_old_ide_name (unsigned int major, unsigned int minor)
1701 char c='a'; /* 97 */ 1702 char c='a'; /* 97 */
1702 int i=IDE0_MAJOR; 1703 int i=IDE0_MAJOR;
1703 1704
1704
1705#ifdef CONFIG_DEVFSD_DEBUG 1705#ifdef CONFIG_DEVFSD_DEBUG
1706 msg_logger( NO_DIE, LOG_INFO, "get_old_ide_name()\n"); 1706 msg_logger( NO_DIE, LOG_INFO, "get_old_ide_name()\n");
1707#endif 1707#endif