static void handler(int signo) { SigTable *sig_tbl; AWKNUM ret; static INSTRUCTION *code; extern int exiting; sig_tbl = sig2ptr(signo); /* make function call instructions */ code = bcalloc(Op_func_call, 2, 0); code->func_name = NULL; /* not needed, func_body will assign */ code->nexti = bcalloc(Op_stop, 1, 0); code->func_body = sig_tbl->user_handler; (code + 1)->expr_count = 1; /* function takes one argument */ PUSH(make_number((AWKNUM) signo)); interpret(code); if (exiting) /* do not assume anything about the user-defined function! */ gawk_exit(exit_val); POP_NUMBER(ret); bcfree(code->nexti); /* Op_stop */ bcfree(code); /* Op_func_call */ return; }
void *bcalloc_array( size_t element_size, ssize_t length, ssize_t nref, cexception_t *ex ) { assert( nref == 1 || nref == 0 ); if( nref > 0 ) { alloccell_t *ptr = bcalloc( REF_SIZE * length, length, length, ex ); if( ptr && nref != 0 ) { ptr[-1].flags |= AF_HAS_REFS; } return ptr; } else { return bcalloc( sizeof(stackunion_t) * length, length, 0, ex ); } }
awk_bool_t make_builtin(const awk_ext_func_t *funcinfo) { NODE *symbol, *f; INSTRUCTION *b; const char *sp; char c; const char *name = funcinfo->name; int count = funcinfo->num_expected_args; sp = name; if (sp == NULL || *sp == '\0') fatal(_("make_builtin: missing function name")); if (! is_letter(*sp)) return awk_false; for (sp++; (c = *sp++) != '\0';) { if (! is_identifier_char(c)) return awk_false; } f = lookup(name); if (f != NULL) { if (f->type == Node_func) { /* user-defined function */ fatal(_("make_builtin: can't redefine function `%s'"), name); } else if (f->type == Node_ext_func) { /* multiple extension() calls etc. */ if (do_lint) lintwarn(_("make_builtin: function `%s' already defined"), name); return awk_false; } else /* variable name etc. */ fatal(_("make_builtin: function name `%s' previously defined"), name); } else if (check_special(name) >= 0) fatal(_("make_builtin: can't use gawk built-in `%s' as function name"), name); if (count < 0) fatal(_("make_builtin: negative argument count for function `%s'"), name); b = bcalloc(Op_symbol, 1, 0); b->extfunc = funcinfo->function; b->expr_count = count; /* NB: extension sub must return something */ symbol = install_symbol(estrdup(name, strlen(name)), Node_ext_func); symbol->code_ptr = b; track_ext_func(name); return awk_true; }
void make_old_builtin(const char *name, NODE *(*func)(int), int count) /* temporary */ { NODE *symbol, *f; INSTRUCTION *b; const char *sp; char c; sp = name; if (sp == NULL || *sp == '\0') fatal(_("extension: missing function name")); if (! is_letter(*sp)) fatal(_("extension: illegal character `%c' in function name `%s'"), *sp, name); for (sp++; (c = *sp++) != '\0';) { if (! is_identifier_char(c)) fatal(_("extension: illegal character `%c' in function name `%s'"), c, name); } f = lookup(name); if (f != NULL) { if (f->type == Node_func) { /* user-defined function */ fatal(_("extension: can't redefine function `%s'"), name); } else if (f->type == Node_ext_func) { /* multiple extension() calls etc. */ if (do_lint) lintwarn(_("extension: function `%s' already defined"), name); return; } else /* variable name etc. */ fatal(_("extension: function name `%s' previously defined"), name); } else if (check_special(name) >= 0) fatal(_("extension: can't use gawk built-in `%s' as function name"), name); if (count < 0) fatal(_("make_builtin: negative argument count for function `%s'"), name); b = bcalloc(Op_symbol, 1, 0); b->builtin = func; b->expr_count = count; /* NB: extension sub must return something */ symbol = install_symbol(estrdup(name, strlen(name)), Node_old_ext_func); symbol->code_ptr = b; track_ext_func(name); }
/* * Interface specific to this fake library to queue a getgrnam_r return. This * assumes that all the pointers in the struct are either pointers to memory * that won't be freed, such as constant strings or persistent memory * allocations, or are NULL. */ void fake_queue_group(const struct group *gr, int status) { struct fake_getgrnam_return *fake, *last; fake = bcalloc(1, sizeof(struct fake_getgrnam_return)); fake->gr = *gr; fake->status = status; if (return_queue == NULL) return_queue = fake; else { for (last = return_queue; last->next != NULL; last = last->next) ; last->next = fake; } }
/* * format the inode blocks */ int iformat(Icache *ic, int f, uint32_t nino, char *name, int bsize, int psize) { int nib; uint32_t bno, i2b, i; Bbuf *bb; Dinode *bi; /* * first format disk allocation */ if(dformat(ic, f, name, bsize, psize) < 0) return -1; fprint(2, "formatting inodes\n"); i2b = (bsize - sizeof(Dihdr))/sizeof(Inode); nib = (nino + i2b - 1)/i2b; for(bno = ic->nab; bno < ic->nab + nib; bno++){ if(dalloc(ic, 0) == Notabno){ fprint(2, "iformat: balloc failed\n"); return -1; } bb = bcalloc(ic, bno); if(bb == 0){ fprint(2, "iformat: bcalloc failed\n"); return -1; } bi = (Dinode*)bb->data; bi->magic = Imagic; bi->nino = nino; for(i = 0; i < i2b; i++) bi->inode[i].inuse = 0; bcmark(ic, bb); } bcsync(ic); return iinit(ic, f, psize, name); }
/* * Obtain Kerberos tickets for the principal specified in config/principal * using the keytab specified in config/keytab, both of which are presumed to * be in tests in either the build or the source tree. Also sets KRB5_KTNAME * and KRB5CCNAME. * * Returns the contents of config/principal in newly allocated memory or NULL * if Kerberos tests are apparently not configured. If Kerberos tests are * configured but something else fails, calls bail. */ struct kerberos_config * kerberos_setup(enum kerberos_needs needs) { char *path; char buffer[BUFSIZ]; FILE *file = NULL; /* If we were called before, clean up after the previous run. */ if (config != NULL) kerberos_cleanup(); config = bcalloc(1, sizeof(struct kerberos_config)); /* * If we have a config/keytab file, set the KRB5CCNAME and KRB5_KTNAME * environment variables and obtain initial tickets. */ config->keytab = test_file_path("config/keytab"); if (config->keytab == NULL) { if (needs == TAP_KRB_NEEDS_KEYTAB || needs == TAP_KRB_NEEDS_BOTH) skip_all("Kerberos tests not configured"); } else { tmpdir_ticket = test_tmpdir(); basprintf(&config->cache, "%s/krb5cc_test", tmpdir_ticket); basprintf(&krb5ccname, "KRB5CCNAME=%s/krb5cc_test", tmpdir_ticket); basprintf(&krb5_ktname, "KRB5_KTNAME=%s", config->keytab); putenv(krb5ccname); putenv(krb5_ktname); kerberos_kinit(); } /* * If we have a config/password file, read it and fill out the relevant * members of our config struct. */ path = test_file_path("config/password"); if (path != NULL) file = fopen(path, "r"); if (file == NULL) { if (needs == TAP_KRB_NEEDS_PASSWORD || needs == TAP_KRB_NEEDS_BOTH) skip_all("Kerberos tests not configured"); } else { if (fgets(buffer, sizeof(buffer), file) == NULL) bail("cannot read %s", path); if (buffer[strlen(buffer) - 1] != '\n') bail("no newline in %s", path); buffer[strlen(buffer) - 1] = '\0'; config->userprinc = bstrdup(buffer); if (fgets(buffer, sizeof(buffer), file) == NULL) bail("cannot read password from %s", path); fclose(file); if (buffer[strlen(buffer) - 1] != '\n') bail("password too long in %s", path); buffer[strlen(buffer) - 1] = '\0'; config->password = bstrdup(buffer); /* * Strip the realm from the principal and set realm and username. * This is not strictly correct; it doesn't cope with escaped @-signs * or enterprise names. */ config->username = bstrdup(config->userprinc); config->realm = strchr(config->username, '@'); if (config->realm == NULL) bail("test principal has no realm"); *config->realm = '\0'; config->realm++; } test_file_path_free(path); /* * If we have PKINIT configuration, read it and fill out the relevant * members of our config struct. */ path = test_file_path("config/pkinit-principal"); if (path != NULL) file = fopen(path, "r"); if (file != NULL) { if (fgets(buffer, sizeof(buffer), file) == NULL) bail("cannot read %s", path); if (buffer[strlen(buffer) - 1] != '\n') bail("no newline in %s", path); buffer[strlen(buffer) - 1] = '\0'; fclose(file); test_file_path_free(path); path = test_file_path("config/pkinit-cert"); if (path != NULL) { config->pkinit_principal = bstrdup(buffer); config->pkinit_cert = bstrdup(path); } } test_file_path_free(path); if (config->pkinit_cert == NULL && (needs & TAP_KRB_NEEDS_PKINIT) != 0) skip_all("PKINIT tests not configured"); /* * Register the cleanup function so that the caller doesn't have to do * explicit cleanup. */ test_cleanup_register(kerberos_cleanup_handler); /* Return the configuration. */ return config; }
void *bcalloc_stackcells( ssize_t length, ssize_t nref, cexception_t *ex ) { return bcalloc( sizeof(stackcell_t) * length, length, nref, ex ); }
void *bcalloc_blob( size_t size, cexception_t *ex ) { return bcalloc( size, size, 0, ex ); }
/* * Allocate and initialize a new struct config. */ static struct pam_config * config_new(void) { return bcalloc(1, sizeof(struct pam_config)); }
int main(void){ memory = bcalloc(sizeof(union memory)); memcheck(); execute(); return 0; }
/* * Start a process and return its status information. The status information * is also stored in the global processes linked list so that it can be * stopped automatically on program exit. * * The boolean argument says whether to start the process under fakeroot. If * true, PATH_FAKEROOT must be defined, generally by Autoconf. If it's not * found, call skip_all. * * This is a helper function for process_start and process_start_fakeroot. */ static struct process * process_start_internal(const char *const argv[], const char *pidfile, bool fakeroot) { size_t i; int log_fd; const char *name; struct timeval tv; struct process *process; const char **fakeroot_argv = NULL; const char *path_fakeroot = PATH_FAKEROOT; /* Check prerequisites. */ if (fakeroot && path_fakeroot[0] == '\0') skip_all("fakeroot not found"); /* Create the process struct and log file. */ process = bcalloc(1, sizeof(struct process)); process->pidfile = bstrdup(pidfile); process->tmpdir = test_tmpdir(); name = strrchr(argv[0], '/'); if (name != NULL) name++; else name = argv[0]; basprintf(&process->logfile, "%s/%s.log.XXXXXX", process->tmpdir, name); log_fd = mkstemp(process->logfile); if (log_fd < 0) sysbail("cannot create log file for %s", argv[0]); /* If using fakeroot, rewrite argv accordingly. */ if (fakeroot) { for (i = 0; argv[i] != NULL; i++) ; fakeroot_argv = bcalloc(2 + i + 1, sizeof(const char *)); fakeroot_argv[0] = path_fakeroot; fakeroot_argv[1] = "--"; for (i = 0; argv[i] != NULL; i++) fakeroot_argv[i + 2] = argv[i]; fakeroot_argv[i + 2] = NULL; argv = fakeroot_argv; } /* * Fork off the child process, redirect its standard output and standard * error to the log file, and then exec the program. */ process->pid = fork(); if (process->pid < 0) sysbail("fork failed"); else if (process->pid == 0) { if (dup2(log_fd, STDOUT_FILENO) < 0) sysbail("cannot redirect standard output"); if (dup2(log_fd, STDERR_FILENO) < 0) sysbail("cannot redirect standard error"); close(log_fd); if (execv(argv[0], (char *const *) argv) < 0) sysbail("exec of %s failed", argv[0]); } close(log_fd); free(fakeroot_argv); /* * In the parent. Wait for the child to start by watching for the PID * file to appear in 100ms intervals. */ for (i = 0; i < PROCESS_WAIT * 10 && access(pidfile, F_OK) != 0; i++) { tv.tv_sec = 0; tv.tv_usec = 100000; select(0, NULL, NULL, NULL, &tv); } /* * If the PID file still hasn't appeared after ten seconds, attempt to * kill the process and then bail. */ if (access(pidfile, F_OK) != 0) { kill(process->pid, SIGTERM); alarm(5); waitpid(process->pid, NULL, 0); alarm(0); bail("cannot start %s", argv[0]); } /* * Read the PID back from the PID file. This usually isn't necessary for * non-forking daemons, but always doing this makes this function general, * and it's required when running under fakeroot. */ if (fakeroot) process->pid = read_pidfile(pidfile); process->is_child = !fakeroot; /* Register the log file as a source of diag messages. */ diag_file_add(process->logfile); /* * Add the process to our global list and set our cleanup handler if this * is the first process we started. */ if (processes == NULL) test_cleanup_register(process_stop_all); process->next = processes; processes = process; /* All done. */ return process; }