Author: obnox
Date: 2007-08-31 09:54:30 +0000 (Fri, 31 Aug 2007)
New Revision: 24827

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24827

Log:
Give smbstatus an initial talloc stackframe.
Rewrite main() so as to exit only at a single point
where the stack frame is freed, too.

Michael


Modified:
   branches/SAMBA_3_2/source/utils/status.c
   branches/SAMBA_3_2_0/source/utils/status.c


Changeset:
Modified: branches/SAMBA_3_2/source/utils/status.c
===================================================================
--- branches/SAMBA_3_2/source/utils/status.c    2007-08-31 09:39:11 UTC (rev 
24826)
+++ branches/SAMBA_3_2/source/utils/status.c    2007-08-31 09:54:30 UTC (rev 
24827)
@@ -294,6 +294,8 @@
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
+       TALLOC_CTX *frame = talloc_stackframe();
+       int ret = 0;
 
        sec_init();
        load_case_tables();
@@ -304,7 +306,8 @@
        
        if (getuid() != geteuid()) {
                d_printf("smbstatus should not be run setuid\n");
-               return(1);
+               ret = 1;
+               goto done;
        }
 
        pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 
@@ -336,7 +339,8 @@
 
        if (!lp_load(dyn_CONFIGFILE,False,False,False,True)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
dyn_CONFIGFILE);
-               return (-1);
+               ret = -1;
+               goto done;
        }
 
        /*
@@ -372,8 +376,9 @@
                        TALLOC_FREE(db);
                }
 
-               if (processes_only) 
-                       exit(0);        
+               if (processes_only) {
+                       goto done;
+               }
        }
   
        if ( show_shares ) {
@@ -381,8 +386,9 @@
                        d_printf("Opened %s\n", lock_path("connections.tdb"));
                }
 
-               if (brief) 
-                       exit(0);
+               if (brief) {
+                       goto done;
+               }
                
                d_printf("\nService      pid     machine       Connected at\n");
                
d_printf("-------------------------------------------------------\n");
@@ -391,23 +397,25 @@
 
                d_printf("\n");
 
-               if ( shares_only )
-                       exit(0);
+               if ( shares_only ) {
+                       goto done;
+               }
        }
 
        if ( show_locks ) {
-               int ret;
+               int result;
 
                if (!locking_init(1)) {
                        d_printf("Can't initialise locking module - exiting\n");
-                       exit(1);
+                       ret = 1;
+                       goto done;
                }
                
-               ret = share_mode_forall(print_share_mode, NULL);
+               result = share_mode_forall(print_share_mode, NULL);
 
-               if (ret == 0) {
+               if (result == 0) {
                        d_printf("No locked files\n");
-               } else if (ret == -1) {
+               } else if (result == -1) {
                        d_printf("locked file list truncated\n");
                }
                
@@ -420,5 +428,7 @@
                locking_end();
        }
 
-       return (0);
+done:
+       TALLOC_FREE(frame);
+       return ret;
 }

Modified: branches/SAMBA_3_2_0/source/utils/status.c
===================================================================
--- branches/SAMBA_3_2_0/source/utils/status.c  2007-08-31 09:39:11 UTC (rev 
24826)
+++ branches/SAMBA_3_2_0/source/utils/status.c  2007-08-31 09:54:30 UTC (rev 
24827)
@@ -294,6 +294,8 @@
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
+       TALLOC_CTX *frame = talloc_stackframe();
+       int ret = 0;
 
        sec_init();
        load_case_tables();
@@ -304,7 +306,8 @@
        
        if (getuid() != geteuid()) {
                d_printf("smbstatus should not be run setuid\n");
-               return(1);
+               ret = 1;
+               goto done;
        }
 
        pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 
@@ -336,7 +339,8 @@
 
        if (!lp_load(dyn_CONFIGFILE,False,False,False,True)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
dyn_CONFIGFILE);
-               return (-1);
+               ret = -1;
+               goto done;
        }
 
        /*
@@ -372,8 +376,9 @@
                        TALLOC_FREE(db);
                }
 
-               if (processes_only) 
-                       exit(0);        
+               if (processes_only) {
+                       goto done;
+               }
        }
   
        if ( show_shares ) {
@@ -381,8 +386,9 @@
                        d_printf("Opened %s\n", lock_path("connections.tdb"));
                }
 
-               if (brief) 
-                       exit(0);
+               if (brief) {
+                       goto done;
+               }
                
                d_printf("\nService      pid     machine       Connected at\n");
                
d_printf("-------------------------------------------------------\n");
@@ -391,23 +397,25 @@
 
                d_printf("\n");
 
-               if ( shares_only )
-                       exit(0);
+               if ( shares_only ) {
+                       goto done;
+               }
        }
 
        if ( show_locks ) {
-               int ret;
+               int result;
 
                if (!locking_init(1)) {
                        d_printf("Can't initialise locking module - exiting\n");
-                       exit(1);
+                       ret = 1;
+                       goto done;
                }
                
-               ret = share_mode_forall(print_share_mode, NULL);
+               result = share_mode_forall(print_share_mode, NULL);
 
-               if (ret == 0) {
+               if (result == 0) {
                        d_printf("No locked files\n");
-               } else if (ret == -1) {
+               } else if (result == -1) {
                        d_printf("locked file list truncated\n");
                }
                
@@ -420,5 +428,7 @@
                locking_end();
        }
 
-       return (0);
+done:
+       TALLOC_FREE(frame);
+       return ret;
 }

Reply via email to