/* Initialize GPU kernel */ void gk_init() { /* Open report file */ if (gpu_kernel_report_file_name[0]) { gpu_kernel_report_file = open_write(gpu_kernel_report_file_name); if (!gpu_kernel_report_file) fatal("%s: cannot open GPU report file ", gpu_kernel_report_file_name); } /* Initialize kernel */ gk = calloc(1, sizeof(struct gk_t)); gk->const_mem = mem_create(); gk->const_mem->safe = 0; gk->global_mem = mem_create(); gk->global_mem->safe = 0; /* Initialize disassembler (decoding tables...) */ amd_disasm_init(); /* Initialize ISA (instruction execution tables...) */ gpu_isa_init(); /* Create platform and device */ opencl_object_list = linked_list_create(); opencl_platform = opencl_platform_create(); opencl_device_create(); }
int main (int argc, char const *const *argv, char const *const *envp) { unsigned int len ; int fd; PROG = "cgjoin" ; if (argc < 3) strerr_dieusage(100, USAGE) ; len = strlen(argv[1]) ; { char path[len + PREFIXLEN + SUFFIXLEN + 1] ; char pid[UINT_FMT + 1] ; unsigned int k ; // format this program's PID as a string k = uint_fmt(pid, getpid()) ; pid[k++] = 0 ; // Build up the path to the cgrup filesystem memcpy(path, PREFIX, PREFIXLEN); memcpy(path + PREFIXLEN, argv[1], len); memcpy(path + PREFIXLEN + len, SUFFIX, SUFFIXLEN); path[PREFIXLEN + len + SUFFIXLEN] = 0 ; doparents(path); // Write the pid to the cgroup's tasks file if ((fd = open_write(path)) < 0) strerr_dief2x(100, "cannot open cgroup tasks file: ", path) ; fd_write(fd, pid, k) ; close(fd) ; } pathexec_run(argv[2], argv+2, envp) ; strerr_dieexec(111, argv[2]) ; }
int main(int argc, char **argv, char **envp) { int retval = 0; /* console */ int ttyfd; if ((ttyfd =open_write("/dev/console")) != 1) { dup2(ttyfd, 0); dup2(ttyfd, 1); dup2(ttyfd, 2); if (ttyfd > 2) close(ttyfd); } printf("Booting!\n"); CHECK(mdev(envp)); CHECK(mount(ROOT_DEV, ROOT_PATH, ROOT_FS, 0, "")); // if kernel doesn't exists CHECK(chdir(ROOT_PATH)); CHECK(chroot(ROOT_PATH)); execve(INIT, NULL, envp); // else //CHECK(kexec(ROOT_PATH)); cleanup: chdir("/"); umount(ROOT_DEV); remove(ROOT_DEV); FAIL(execve(INIT_ANDROID, argv, envp)); return retval; }
void f_init(char **script) { int i; int fd; for (i = 0;script[i];++i) ; f = (int *) alloc(i * sizeof(*f)); if (!f) strerr_die2x(111,FATAL,"out of memory"); for (i = 0;script[i];++i) { fd = -1; if (script[i][0] == '=') { if (fchdir(fdstartdir) == -1) strerr_die2sys(111,FATAL,"unable to switch to starting directory: "); fd = open_append(script[i] + 1); if (fd == -1) strerr_die4sys(111,FATAL,"unable to create ",script[i] + 1,": "); close(fd); fd = open_write(script[i] + 1); if (fd == -1) strerr_die4sys(111,FATAL,"unable to write ",script[i] + 1,": "); coe(fd); } f[i] = fd; } }
static int svstatus_get(void) { if ((fd = open_write("supervise/ok")) == -1) { if (errno == ENODEV) { *acts == 'x' ? ok("runsv not running") : failx("runsv not running"); return 0; } warn_cannot("open supervise/ok"); return -1; } close(fd); if ((fd = open_read("supervise/status")) == -1) { warn_cannot("open supervise/status"); return -1; } r = read(fd, svstatus, 20); close(fd); switch (r) { case 20: break; case -1: warn_cannot("read supervise/status"); return -1; default: warnx_cannot("read supervise/status: bad format"); return -1; } return 1; }
static int do_dm_close (const char *path) { struct dm_ioctl dm = { .version = { DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL }, .data_size = sizeof (dm) }; struct stat st; int fd; int r; verbose_do ("Removing block device ", path); if (stat (path, &st) < 0) { verbose_fail (errno); return -1; } dm.dev = st.st_rdev; fd = open_write ("/dev/mapper/control"); if (fd < 0) { verbose_fail (errno); return -1; } r = ioctl (fd, DM_DEV_REMOVE, &dm); if (r < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Block device removed", path, 1); fd_close (fd); return r; }
int main(int argc,char **argv) { struct stat st; dir = argv[1]; if (!dir || argv[2]) strerr_die1x(100,"supervise: usage: supervise dir"); if (pipe(selfpipe) == -1) strerr_die4sys(111,FATAL,"unable to create pipe for ",dir,": "); coe(selfpipe[0]); coe(selfpipe[1]); ndelay_on(selfpipe[0]); ndelay_on(selfpipe[1]); sig_block(sig_child); sig_catch(sig_child,trigger); if (chdir(dir) == -1) strerr_die4sys(111,FATAL,"unable to chdir to ",dir,": "); if (stat("down",&st) != -1) flagwantup = 0; else if (errno != error_noent) strerr_die4sys(111,FATAL,"unable to stat ",dir,"/down: "); mkdir("supervise",0700); fdlock = open_append("supervise/lock"); if ((fdlock == -1) || (lock_exnb(fdlock) == -1)) strerr_die4sys(111,FATAL,"unable to acquire ",dir,"/supervise/lock: "); coe(fdlock); fifo_make("supervise/control",0600); fdcontrol = open_read("supervise/control"); if (fdcontrol == -1) strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/control: "); coe(fdcontrol); ndelay_on(fdcontrol); /* shouldn't be necessary */ fdcontrolwrite = open_write("supervise/control"); if (fdcontrolwrite == -1) strerr_die4sys(111,FATAL,"unable to write ",dir,"/supervise/control: "); coe(fdcontrolwrite); pidchange(); announce(); fifo_make("supervise/ok",0600); fdok = open_read("supervise/ok"); if (fdok == -1) strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/ok: "); coe(fdok); if (!flagwant || flagwantup) trystart(); doit(); announce(); _exit(0); }
void generate_ymp(config_t config, const char *pkgname, char *ympname) { char dirname[FILEPATH_MAX]; char filename[FILEPATH_MAX]; FILE *ymp; int r; snprintf(dirname, FILEPATH_MAX, "%s/%s", config.dir, YMP_DIR); create_dir(dirname); snprintf(ympname, FILEPATH_MAX, "%s/%s.ymp", YMP_DIR, pkgname); snprintf(filename, FILEPATH_MAX, "%s/%s", config.dir, ympname); if (exists(filename)) return; ymp = open_write(filename, "generate_ymp"); fprintf(ymp, "<metapackage" " xmlns:os=\"http://opensuse.org/Standards/One_Click_Install\"" " xmlns=\"http://opensuse.org/Standards/One_Click_Install\">\n"); for (r = 0; r < config.nrepositories; r++) { fprintf(ymp, " <group distversion=\"%s\">\n", config.repositories[r][0]); fprintf(ymp, " <repositories>\n"); fprintf(ymp, " <repository recomended=\"true\" format=\"yast\">\n"); fprintf(ymp, " <name>M17N:fonts (%s)</name>\n", config.repositories[r][0]); fprintf(ymp, " <summary>\n"); fprintf(ymp, " %s repository for %s\n", config.location, config.repositories[r][0]); fprintf(ymp, " </summary>\n"); fprintf(ymp, " <description>\n"); fprintf(ymp, " This repository contains fonts located in\n"); fprintf(ymp, " %s installable on %s system.\n", config.location, config.repositories[r][0]); fprintf(ymp, " </description>\n"); fprintf(ymp, " <url>%s</url>\n", config.repositories[r][1]); fprintf(ymp, " </repository>\n"); fprintf(ymp, " </repositories>\n"); fprintf(ymp, " <software>\n"); fprintf(ymp, " <item>\n"); fprintf(ymp, " <name>%s</name>\n", pkgname); fprintf(ymp, " <summary>\n"); fprintf(ymp, " Font package from %s\n", config.location); fprintf(ymp, " </summary>\n"); fprintf(ymp, " <description>\n"); fprintf(ymp, " Latest version of package %s in %s.\n", pkgname, config.location); fprintf(ymp, " </description>\n"); fprintf(ymp, " </item>\n"); fprintf(ymp, " </software>\n"); fprintf(ymp, " </group>\n"); } fprintf(ymp, "</metapackage>\n"); fclose(ymp); return; }
/* test if close-on-exec works for open_write() */ static void test2(void) { int fd; close(1); fd = open_write("opentest.data"); if (fd != 1) fail("unable to open opentest.data for writing"); cat(); }
int sv_stat(sv_stat_t *svst, char *path) { array_t full_path = ARRAY_INIT(1); int ok_fd; struct stat st; int status_fd; int32_t tmp; /* Check if 'down' exist indicating that the service isn't started when * supervise starts up. */ if (array_path(&full_path, path, "down")) { array_reset(&full_path); errno = ENOMEM; return -1; } if (stat(array_start(&full_path), &st) == -1) { if (errno != ENOENT) { array_reset(&full_path); return ESVSTATDOWN; } svst->autostart = 1; } else svst->autostart = 0; /* Attempt to open the supervise/ok fifo to see if supervise is actually * running. */ if (array_path(&full_path, path, SUPERVISE_OK_PATH)) { array_reset(&full_path); errno = ENOMEM; return -1; } ok_fd = open_write(array_start(&full_path)); if (ok_fd == -1) { array_reset(&full_path); if (errno == ENODEV) return ESVNOTRUN; return ESVOPENOK; } close(ok_fd); /* Load the contents of the supervise/status file. */ if (array_path(&full_path, path, SUPERVISE_STATUS_PATH)) { array_reset(&full_path); errno = ENOMEM; return -1; } if (sv_stat_load(svst, array_start(&full_path)) == -1) { array_reset(&full_path); return -1; } array_reset(&full_path); return 0; }
void trigger_set() { if (fd != -1) close(fd); #ifdef HASNAMEDPIPEBUG1 if (fdw != -1) close(fdw); #endif fd = open_read("lock/trigger"); #ifdef HASNAMEDPIPEBUG1 fdw = open_write("lock/trigger"); #endif }
int ftrig1_make (ftrig1 *f, char const *path) { ftrig1 ff = FTRIG1_ZERO ; unsigned int pathlen = str_len(path) ; int e = 0 ; char tmp[pathlen + 46 + FTRIG1_PREFIXLEN] ; byte_copy(tmp, pathlen, path) ; tmp[pathlen] = '/' ; tmp[pathlen+1] = '.' ; byte_copy(tmp + pathlen + 2, FTRIG1_PREFIXLEN, FTRIG1_PREFIX) ; tmp[pathlen + 2 + FTRIG1_PREFIXLEN] = ':' ; if (!timestamp(tmp + pathlen + 3 + FTRIG1_PREFIXLEN)) return 0 ; tmp[pathlen + 28 + FTRIG1_PREFIXLEN] = ':' ; if (random_name(tmp + pathlen + 29 + FTRIG1_PREFIXLEN, 16) < 16) return 0 ; tmp[pathlen + 45 + FTRIG1_PREFIXLEN] = 0 ; { mode_t m = umask(0) ; if (fifo_make(tmp, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH) == -1) { umask(m) ; return 0 ; } umask(m) ; } if (!stralloc_catb(&ff.name, tmp, pathlen+1)) { e = errno ; goto err0 ; } if (!stralloc_catb(&ff.name, tmp + pathlen + 2, FTRIG1_PREFIXLEN + 44)) { e = errno ; goto err1 ; } ff.fd = open_read(tmp) ; if (ff.fd == -1) { e = errno ; goto err1 ; } ff.fdw = open_write(tmp) ; if (ff.fdw == -1) { e = errno ; goto err2 ; } if (rename(tmp, ff.name.s) == -1) goto err3 ; *f = ff ; return 1 ; err3: e = errno ; fd_close(ff.fdw) ; err2: fd_close(ff.fd) ; err1: stralloc_free(&ff.name) ; err0: unlink(tmp) ; errno = e ; return 0 ; }
/* Write data to an IO object. If offset is -1, write at the object maintained file pointer. If the object is not seekable, offset is ignored. The amount successfully written is returned in amount. A given user should not have more than one outstanding io_write on an object at a time; servers implement congestion control by delaying responses to io_write. Servers may drop data (returning ENOBUFS) if they recevie more than one write when not prepared for it. */ error_t trivfs_S_io_write (struct trivfs_protid *cred, mach_port_t reply, mach_msg_type_name_t reply_type, char *data, mach_msg_type_number_t data_len, loff_t offs, mach_msg_type_number_t *amount) { if (! cred) return EOPNOTSUPP; else if (! (cred->po->openmodes & O_WRITE)) return EBADF; else return open_write ((struct open *)cred->po->hook, offs, (void *)data, data_len, amount); }
TEST_FIXTURE(page_blob_test_base, page_blob_write_stream_access_condition) { m_blob.create(0, 0, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); auto missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob1")); CHECK_THROW(missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob2")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob3")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob4")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_page_blob_reference(_XPLATSTR("missing_blob5")); missing_blob.open_write(0, 0, azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(0, 0, azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); }
int main(int argc,const char *const *argv) { int opt; int fd; const char *dir; sig_ignore(sig_pipe); while ((opt = getopt(argc,argv,"?vudopchaitkx")) != opteof) if (opt == 'v'){ puts("version: 0.76d"); exit(0); } else if (opt == '?') strerr_die1x(100,"svc options: u up, d down, o once, x exit, p pause, c continue, h hup, a alarm, i interrupt, t term, k kill"); else if (datalen < sizeof data) if (byte_chr(data,datalen,opt) == datalen) data[datalen++] = opt; argv += optind; fdorigdir = open_read("."); if (fdorigdir == -1) strerr_die2sys(111,FATAL,"unable to open current directory: "); while (dir = *argv++) { if (chdir(dir) == -1) strerr_warn4(WARNING,"unable to chdir to ",dir,": ",&strerr_sys); else { fd = open_write("supervise/control"); if (fd == -1) if (errno == error_nodevice) strerr_warn4(WARNING,"unable to control ",dir,": supervise not running",0); else strerr_warn4(WARNING,"unable to control ",dir,": ",&strerr_sys); else { ndelay_off(fd); buffer_init(&b,buffer_unixwrite,fd,bspace,sizeof bspace); if (buffer_putflush(&b,data,datalen) == -1) strerr_warn4(WARNING,"error writing commands to ",dir,": ",&strerr_sys); close(fd); } } if (fchdir(fdorigdir) == -1) strerr_die2sys(111,FATAL,"unable to set directory: "); } _exit(0); }
int s6_svc_write (char const *fifo, char const *data, unsigned int datalen) { int fd = open_write(fifo) ; if (fd < 0) return (errno == ENXIO) ? 0 : -1 ; else if (ndelay_off(fd) == -1) return -1 ; else if (fd_write(fd, data, datalen) == -1) { register int e = errno ; fd_close(fd) ; errno = e ; return -1 ; } fd_close(fd) ; return 1 ; }
void openandwrite(char *filename, stralloc *sa) { int fdfifo; /* we need this to keep the fifo from beeing closed */ fdfifo = open_write(filename); if (fdfifo == -1) strerr_warn3("ddnsd: unable to open ", filename, "for writing: ", &strerr_sys); // XXX is 5 second timeout a good idea? if(timeoutwrite(5, fdfifo, sa->s, sa->len) != sa->len) strerr_warn3("can't write to fifo ", filename, ": ", &strerr_sys); close(fdfifo); }
DirectFile::DirectFile (string const &path, IoMode mode_, size_t max_size_) : mode(mode_), max_size(max_size_), fd(-1), index(0) { if (mode == MODE_READ) { open_read(path); } else if (mode == MODE_WRITE) { open_write(path); } else { CHECK(0); } }
bool hfile::save(void* data, int datasize) { // Go Ahead And Open The File For Reading //---------------------------------------- bool auto_opened = false; if (!is_open()) { if (!open_write()) { return false; } auto_opened = true; } // Make Sure That The File Is Readable //------------------------------------- SOpenFile& sfile = Pool()[mHandle]; if (sfile.mForRead) { assert("HFILE: Unable to save to a file that is opened for read"==0); if (auto_opened) { close(); } return false; } // Write The Actual Object //------------------------- if (!HFILEwrite(sfile.mHandle, data, datasize)) { assert("HFILE: Unable To Write File Data"==0); if (auto_opened) { close(); } return false; } if (auto_opened) { close(); } return true; }
TEST_FIXTURE(block_blob_test_base, block_blob_write_stream_access_condition) { m_blob.upload_block_list(std::vector<azure::storage::block_list_item>(), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); auto missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob1")); CHECK_THROW(missing_blob.open_write(azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob2")); missing_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob3")); missing_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob4")); missing_blob.open_write(azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob5")); missing_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); m_blob.open_write(azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(missing_blob.properties().etag()), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); auto stream = m_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); m_blob.open_write(azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); m_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() + utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context).close().wait(); CHECK_THROW(m_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified() - utility::datetime::from_minutes(1)), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception); stream = m_blob.open_write(azure::storage::access_condition::generate_if_match_condition(m_blob.properties().etag()), azure::storage::blob_request_options(), m_context); m_blob.upload_properties(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); missing_blob = m_container.get_block_blob_reference(_XPLATSTR("missing_blob6")); stream = missing_blob.open_write(azure::storage::access_condition::generate_if_none_match_condition(_XPLATSTR("*")), azure::storage::blob_request_options(), m_context); missing_blob.upload_block_list(std::vector<azure::storage::block_list_item>(), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); stream = m_blob.open_write(azure::storage::access_condition::generate_if_not_modified_since_condition(m_blob.properties().last_modified()), azure::storage::blob_request_options(), m_context); std::this_thread::sleep_for(std::chrono::seconds(1)); m_blob.upload_properties(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_THROW(stream.close().wait(), azure::storage::storage_exception); }
int control(char *a) { if (svstatus_get() <= 0) return(-1); if (svstatus[17] == *a) if (*a != 'd' || svstatus[18] == 1) return(0); /* once w/o term */ if ((fd =open_write("supervise/control")) == -1) { if (errno != error_nodevice) warn("unable to open supervise/control"); else *a == 'x' ? ok("runsv not running") : failx("runsv not running"); return(-1); } r =write(fd, a, str_len(a)); close(fd); if (r != str_len(a)) { warn("unable to write to supervise/control"); return(-1); } return(1); }
static int control(char *a) { if (svstatus_get() <= 0) return -1; if (svstatus[17] == *a) return 0; if ((fd = open_write("supervise/control")) == -1) { if (errno != ENODEV) warn_cannot("open supervise/control"); else *a == 'x' ? ok("runsv not running") : failx("runsv not running"); return -1; } r = write(fd, a, strlen(a)); close(fd); if (r != strlen(a)) { warn_cannot("write to supervise/control"); return -1; } return 1; }
/* Signal handlers */ static void sim_signal_handler(int signum) { FILE *f; switch (signum) { case SIGINT: //if (sigint_received) // abort(); sigint_received = 1; fprintf(stderr, "SIGINT received\n"); signal(SIGINT, sim_signal_handler); printf("Don't do that\n"); break; case SIGABRT: signal(SIGABRT, SIG_DFL); fprintf(stderr, "cycle %lld: aborted\n", (long long) sim_cycle); f = open_write(inst_stat_file); if (f) isa_inst_stat_dump(f); isa_dump(stderr); ke_dump(stderr); exit(1); break; case SIGFPE: printf("\n Inside signal handler for signal floating point error**"); printf("\n Inside signal handler for signal floating point error**"); signal(SIGFPE, SIG_DFL); break; case SIGSEGV: signal(SIGSEGV, SIG_DFL); printf ( "You are here in sim_signal_handler \nsegmentation fault\n"); exit(0); break; case SIGUSR1: printf("\n Inside signal handler for signal named SIGUSR1"); printf("\ndoing nothing"); break; } }
int cdbb_open_write(struct cdbb *a, const char *f) { int fp; unlink(f); fp = open_write(f); if (fp < 0) return -1; a->w = malloc(sizeof(struct cdb_make)); if (a->w == NULL) { close(fp); return -1; } cdb_make_start(a->w, fp); a->fnum = 0; a->tnum = 0; return fp; }
int main() { int fd; int i; if (chdir(auto_qmail) == -1) strerr_die4sys(111,FATAL,"unable to chdir to ",auto_qmail,": "); if (chdir("queue/lock") == -1) strerr_die4sys(111,FATAL,"unable to chdir to ",auto_qmail,"/queue/lock: "); fd = open_write("tcpto"); if (fd == -1) strerr_die4sys(111,FATAL,"unable to write ",auto_qmail,"/queue/lock/tcpto: "); if (lock_ex(fd) == -1) strerr_die4sys(111,FATAL,"unable to lock ",auto_qmail,"/queue/lock/tcpto: "); substdio_fdbuf(&ss,write,fd,buf,sizeof buf); for (i = 0;i < sizeof buf;++i) substdio_put(&ss,"",1); if (substdio_flush(&ss) == -1) strerr_die4sys(111,FATAL,"unable to clear ",auto_qmail,"/queue/lock/tcpto: "); _exit(0); }
int svstatus_get() { if ((fd =open_write("supervise/ok")) == -1) { if (errno == error_nodevice) { *acts == 'x' ? ok("runsv not running") : failx("runsv not running"); return(0); } warn("unable to open supervise/ok"); return(-1); } close(fd); if ((fd =open_read("supervise/status")) == -1) { warn("unable to open supervise/status"); return(-1); } r =read(fd, svstatus, 20); close(fd); switch(r) { case 20: break; case -1: warn("unable to read supervise/status"); return(-1); default: warnx("unable to read supervise/status: bad format"); return(-1); } return(1); }
int main(int argc,char **argv) { int fd; const char *fnok; if (!argv[1]) strerr_die1x(100,"svok: usage: svok dir"); if (chdir(argv[1]) == -1) strerr_die3sys(111,FATAL,"unable to chdir to ",argv[1]); if (!svpath_init()) strerr_die3sys(111,FATAL,"unable to setup control path for ",argv[1]); if ((fnok = svpath_make("/ok")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_write(fnok); if (fd == -1) { if (errno == error_noent) _exit(100); if (errno == error_nodevice) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fnok); } _exit(0); }
void close_callback() { // 必须在此处删除该动态分配的回调类对象以防止内存泄露 if (ifile_ >= nfiles_) { printf("write %s over!, ifile: %d, nfiles: %d\r\n", filepath_.c_str(), ifile_, nfiles_); delete this; __nok++; } else { //printf("ifile_: %d, nfiles_: %d\r\n", ifile_, nfiles_); nwrite_ = 0; delay_ = 0; // 重新打开一个新的异步流句柄 if (open_write() == false) { printf("open file error\r\n"); exit (1); } } }
void pbsexec(void) { char *(args[3]); int child, wstat; if (pbstool == 0 || *pbstool == 0) return; if (env_get("NOPBS")) return; switch (child = fork()) { case -1: return; case 0: /* the pbstool may not read or write to the connection */ close(0); open_read("/dev/null"); close(1); open_write("/dev/null"); close(3); args[0] = pbstool; args[1] = 0; execvp(*args, args); _exit(111); } wait_pid(&wstat,child); if (wait_crashed(wstat)) logit(2, "pbsexec: %s crashed\n", pbstool); else if (wait_exitcode(wstat)) logit(2, "pbsexec: %s failed, exit code %d\n", pbstool, wait_exitcode(wstat)); else logit(64, "pbsexec: %s OK\n", pbstool); return; }
static void set_governor_for_cpu(const char* governor, int cpu) { DEBUGF("DEBUG %s: governor: %s, cpu: %d.", __func__, governor, cpu); char scaling_governor_interface[64]; snprintf(scaling_governor_interface, sizeof(scaling_governor_interface), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpu); FILE *f = open_write(scaling_governor_interface); if(f == NULL) { return; } if(fprintf(f, "%s", governor) < 1) { DEBUGF("ERROR %s: Write failed for %s.", __func__, scaling_governor_interface); } fclose(f); }