Whamcloud - gitweb
ChangeLog, fsck.8.in:
[tools/e2fsprogs.git] / misc / chattr.c
index 45e2c8f..848c1d5 100644 (file)
  * 93/10/30    - Creation
  * 93/11/13    - Replace stat() calls by lstat() to avoid loops
  * 94/02/27    - Integrated in Ted's distribution
+ * 98/12/29    - Ignore symlinks when working recursively (G M Sipe)
+ * 98/12/29    - Display version info only when -V specified (G M Sipe)
  */
 
 #include <sys/types.h>
 #include <dirent.h>
 #include <fcntl.h>
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
@@ -53,13 +53,13 @@ unsigned long af;
 unsigned long rf;
 unsigned long sf;
 
-static void volatile fatal_error (const char * fmt_string, int errcode)
+static void fatal_error(const char * fmt_string, int errcode)
 {
        fprintf (stderr, fmt_string, program_name);
        exit (errcode);
 }
 
-#define usage() fatal_error ("usage: %s [-RV] [-+=acdisSu] [-v version] files...\n", \
+#define usage() fatal_error("usage: %s [-RV] [-+=AacdisSu] [-v version] files...\n", \
                             1)
 
 static int decode_arg (int * i, int argc, char ** argv)
@@ -239,6 +239,8 @@ static void change_attributes (const char * name)
                com_err (program_name, errno, "while stating %s", name);
                return;
        }
+       if (S_ISLNK(st.st_mode) && recursive)
+               return;
        if (set)
        {
                if (verbose)
@@ -301,14 +303,11 @@ static int chattr_dir_proc (const char * dir_name, struct dirent * de, void * pr
        return 0;
 }
 
-void main (int argc, char ** argv)
+int main (int argc, char ** argv)
 {
        int i, j;
        int end_arg = 0;
 
-       fprintf (stderr, "chattr %s, %s for EXT2 FS %s, %s\n",
-                E2FSPROGS_VERSION, E2FSPROGS_DATE,
-                EXT2FS_VERSION, EXT2FS_DATE);
        if (argc && *argv)
                program_name = *argv;
        i = 1;
@@ -331,6 +330,11 @@ void main (int argc, char ** argv)
                fprintf (stderr, "Must use '-v', =, - or +\n");
                exit (1);
        }
+       if (verbose)
+               fprintf (stderr, "chattr %s, %s for EXT2 FS %s, %s\n",
+                        E2FSPROGS_VERSION, E2FSPROGS_DATE,
+                        EXT2FS_VERSION, EXT2FS_DATE);
        for (j = i; j < argc; j++)
                change_attributes (argv[j]);
+       exit(0);
 }