s3-util: for convenience, provide format comments in tdb_unpack().
[jra/samba/.git] / source3 / torture / nbio.c
index 2d519b40bacefdc57c228865dcfd3e05aed997b0..a010c80985e6d9ec3abe839c29a4c15a1242f135 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#define NO_SYSLOG
-
 #include "includes.h"
 
 #define MAX_FILES 1000
@@ -36,7 +33,7 @@ static struct {
        int handle;
 } ftable[MAX_FILES];
 
-static struct {
+static struct children {
        double bytes_in, bytes_out;
        int line;
        int done;
@@ -52,7 +49,7 @@ double nbio_total(void)
        return total;
 }
 
-void nb_alarm(void)
+void nb_alarm(int ignore)
 {
        int i;
        int lines=0, num_clients=0;
@@ -72,13 +69,14 @@ void nb_alarm(void)
 void nbio_shmem(int n)
 {
        nprocs = n;
-       children = shm_setup(sizeof(*children) * nprocs);
+       children = (struct children *)shm_setup(sizeof(*children) * nprocs);
        if (!children) {
                printf("Failed to setup shared memory!\n");
                exit(1);
        }
 }
 
+#if 0
 static int ne_find_handle(int handle)
 {
        int i;
@@ -88,6 +86,7 @@ static int ne_find_handle(int handle)
        }
        return -1;
 }
+#endif
 
 static int find_handle(int handle)
 {
@@ -112,7 +111,9 @@ static void sigsegv(int sig)
        printf("segv at line %d\n", line_count);
        slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d", 
                (int)getpid(), (int)getpid());
-       system(line);
+       if (system(line) == -1) {
+               printf("system() failed\n");
+       }
        exit(1);
 }
 
@@ -125,7 +126,7 @@ void nb_setup(struct cli_state *cli)
 }
 
 
-void nb_unlink(char *fname)
+void nb_unlink(const char *fname)
 {
        if (!cli_unlink(c, fname)) {
 #if NBDEBUG
@@ -136,7 +137,7 @@ void nb_unlink(char *fname)
 }
 
 
-void nb_createx(char *fname, 
+void nb_createx(const char *fname, 
                unsigned create_options, unsigned create_disposition, int handle)
 {
        int fd, i;
@@ -148,12 +149,12 @@ void nb_createx(char *fname,
                desired_access = FILE_READ_DATA | FILE_WRITE_DATA;
        }
 
-       fd = cli_nt_create_full(c, fname, 
+       fd = cli_nt_create_full(c, fname, 0, 
                                desired_access,
                                0x0,
                                FILE_SHARE_READ|FILE_SHARE_WRITE, 
                                create_disposition, 
-                               create_options);
+                               create_options, 0);
        if (fd == -1 && handle != -1) {
                printf("ERROR: cli_nt_create_full failed for %s - %s\n",
                       fname, cli_errstr(c));
@@ -217,7 +218,7 @@ void nb_close(int handle)
        ftable[i].handle = 0;
 }
 
-void nb_rmdir(char *fname)
+void nb_rmdir(const char *fname)
 {
        if (!cli_rmdir(c, fname)) {
                printf("ERROR: rmdir %s failed (%s)\n", 
@@ -226,17 +227,17 @@ void nb_rmdir(char *fname)
        }
 }
 
-void nb_rename(char *old, char *new)
+void nb_rename(const char *oldname, const char *newname)
 {
-       if (!cli_rename(c, old, new)) {
+       if (!cli_rename(c, oldname, newname)) {
                printf("ERROR: rename %s %s failed (%s)\n", 
-                      old, new, cli_errstr(c));
+                      oldname, newname, cli_errstr(c));
                exit(1);
        }
 }
 
 
-void nb_qpathinfo(char *fname)
+void nb_qpathinfo(const char *fname)
 {
        cli_qpathinfo(c, fname, NULL, NULL, NULL, NULL, NULL);
 }
@@ -255,12 +256,12 @@ void nb_qfsinfo(int level)
        cli_dskattr(c, &bsize, &total, &avail);
 }
 
-static void find_fn(file_info *finfo, const char *name, void *state)
+static void find_fn(const char *mnt, file_info *finfo, const char *name, void *state)
 {
        /* noop */
 }
 
-void nb_findfirst(char *mask)
+void nb_findfirst(const char *mask)
 {
        cli_list(c, mask, 0, find_fn, NULL);
 }
@@ -274,17 +275,23 @@ void nb_flush(int fnum)
 
 static int total_deleted;
 
-static void delete_fn(file_info *finfo, const char *name, void *state)
+static void delete_fn(const char *mnt, file_info *finfo, const char *name, void *state)
 {
        char *s, *n;
        if (finfo->name[0] == '.') return;
 
-       n = strdup(name);
+       n = SMB_STRDUP(name);
        n[strlen(n)-1] = 0;
-       asprintf(&s, "%s%s", n, finfo->name);
+       if (asprintf(&s, "%s%s", n, finfo->name) == -1) {
+               printf("asprintf failed\n");
+               return;
+       }
        if (finfo->mode & aDIR) {
                char *s2;
-               asprintf(&s2, "%s\\*", s);
+               if (asprintf(&s2, "%s\\*", s) == -1) {
+                       printf("asprintf failed\n");
+                       return;
+               }
                cli_list(c, s2, aDIR, delete_fn, NULL);
                nb_rmdir(s);
        } else {
@@ -295,10 +302,13 @@ static void delete_fn(file_info *finfo, const char *name, void *state)
        free(n);
 }
 
-void nb_deltree(char *dname)
+void nb_deltree(const char *dname)
 {
        char *mask;
-       asprintf(&mask, "%s\\*", dname);
+       if (asprintf(&mask, "%s\\*", dname) == -1) {
+               printf("asprintf failed\n");
+               return;
+       }
 
        total_deleted = 0;
        cli_list(c, mask, aDIR, delete_fn, NULL);