int saveenv(void) { struct block_dev_desc_t *sata = NULL; if (sata_curr_device == -1) { if (sata_initialize()) return 1; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return 1; } sata = sata_get_dev(sata_curr_device); printf("Writing to SATA(%d)... ", sata_curr_device); if (write_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
static int env_sata_save(void) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); struct blk_desc *sata = NULL; int env_sata, ret; if (sata_initialize()) return 1; env_sata = sata_get_env_dev(); sata = sata_get_dev(env_sata); if (sata == NULL) { printf("Unknown SATA(%d) device for environment!\n", env_sata); return 1; } ret = env_export(env_new); if (ret) return 1; printf("Writing to SATA(%d)...", env_sata); if (write_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, &env_new)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
/** * If the ENV is not exist, create it. * @see flash_write_env * * @param key ENV name * @param value ENV value * * @return result */ static FlashErrCode create_env(const char *key, const char *value) { FlashErrCode result = FLASH_NO_ERR; FLASH_ASSERT(key); FLASH_ASSERT(value); if (*key == NULL) { FLASH_INFO("Flash ENV name must be not empty!\n"); return FLASH_ENV_NAME_ERR; } if (strstr(key, "=")) { FLASH_INFO("Flash ENV name can't contain '='.\n"); return FLASH_ENV_NAME_ERR; } /* find ENV */ if (find_env(key)) { FLASH_INFO("The name of \"%s\" is already exist.\n", key); return FLASH_ENV_NAME_EXIST; } /* write ENV at the end of cache */ result = write_env(key, value); return result; }
int saveenv(void) { env_t env_new; ssize_t len; char *res; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); u32 offset; if (init_mmc_for_env(mmc)) return 1; if(mmc_get_env_addr(mmc, &offset)) return 1; res = (char *)&env_new.data; len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } env_new.crc = crc32(0, env_new.data, ENV_SIZE); printf("Writing to MMC(%d)... ", CONFIG_SYS_MMC_ENV_DEV); if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)&env_new)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
/** * handles a client request */ static int write_request(stream_t *s, request_rec *r, config_t *config, cluster_t *cluster, int *keepalive, int session_index, int backup_index, char *ip, char *session_id) { int len; int code; int write_length; time_t new_time; time_t start_time = r->request_time; hmux_start_channel(s, 1); write_env(s, r, session_id); write_headers(s, r); write_added_headers(s, r); /* read post data */ if (ap_should_client_block(r)) { char buf[BUF_LENGTH]; int ack_size = s->cluster_srun->srun->send_buffer_size; int send_length = 0; while ((len = ap_get_client_block(r, buf, BUF_LENGTH)) > 0) { /* ap_reset_timeout(r); */ cse_write_packet(s, HMUX_DATA, buf, len); send_length += len; if (ack_size <= send_length) { send_length = 0; cse_write_byte(s, HMUX_YIELD); code = send_data(s, r, HMUX_ACK, keepalive); if (code < 0 || code == HMUX_QUIT || code == HMUX_EXIT) break; } } } cse_write_byte(s, HMUX_QUIT); code = send_data(s, r, HMUX_QUIT, keepalive); if (code >= 0 || s->sent_data) return code; write_length = s->write_length; if (cse_open_connection(s, cluster, session_index, backup_index, r->request_time, r->pool)) { s->write_length = write_length; LOG(("retry connection %d\n", s->socket)); return send_data(s, r, HMUX_QUIT, keepalive); } else { return HTTP_SERVICE_UNAVAILABLE; } }
int saveenv(void) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); ssize_t len; char *res; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); u32 offset; int ret, copy = 0; if (init_mmc_for_env(mmc)) return 1; res = (char *)&env_new->data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); ret = 1; goto fini; } env_new->crc = crc32(0, &env_new->data[0], ENV_SIZE); #ifdef CONFIG_ENV_OFFSET_REDUND env_new->flags = ++env_flags; /* increase the serial */ if (gd->env_valid == 1) copy = 1; #endif if (mmc_get_env_addr(mmc, copy, &offset)) { ret = 1; goto fini; } printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", CONFIG_SYS_MMC_ENV_DEV); if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) { puts("failed\n"); ret = 1; goto fini; } puts("done\n"); ret = 0; #ifdef CONFIG_ENV_OFFSET_REDUND gd->env_valid = gd->env_valid == 2 ? 1 : 2; #endif fini: fini_mmc_for_env(mmc); return ret; }
static void make_file(const char* filename, int save_cwd) { int fd; int saved_umask; int mode; char tmpname[256]; char* ptr; struct timeval t; switch (do_chdir(save_cwd)) { case 0: return; case 2: mode = 0666; break; default: mode = 0600; break; } saved_umask = umask(0); gettimeofday(&t, 0); ptr = tmpname; *ptr++ = '.'; ptr = utoa2(t.tv_sec, ptr); *ptr++ = '.'; ptr = utoa2(t.tv_usec, ptr); *ptr++ = ':'; ptr = utoa2(getpid(), ptr); if ((fd = open(tmpname, O_WRONLY|O_CREAT|O_EXCL, mode)) == -1) warn3sys("Could not open '", tmpname, "' for writing"); else { if (!write_env(fd, "USER") || !write_env(fd, "DOMAIN") || close(fd) == -1) { warn3sys("Could not write to '", filename, "'"); close(fd); } else if (rename(tmpname, filename) == -1) warn5sys("Could not rename '", tmpname, "' to '", filename, "'"); unlink(tmpname); } if (save_cwd) { umask(saved_umask); do_chdir_back(); } }
int saveenv(void) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int dev = mmc_get_env_dev(); struct mmc *mmc = find_mmc_device(dev); u32 offset; int ret, copy = 0; const char *errmsg; errmsg = init_mmc_for_env(mmc); if (errmsg) { printf("%s\n", errmsg); return 1; } ret = env_export(env_new); if (ret) goto fini; #ifdef CONFIG_ENV_OFFSET_REDUND env_new->flags = ++env_flags; /* increase the serial */ if (gd->env_valid == 1) copy = 1; #endif if (mmc_get_env_addr(mmc, copy, &offset)) { ret = 1; goto fini; } printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "", dev); if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) { puts("failed\n"); ret = 1; goto fini; } puts("done\n"); ret = 0; #ifdef CONFIG_ENV_OFFSET_REDUND gd->env_valid = gd->env_valid == 2 ? 1 : 2; #endif fini: fini_mmc_for_env(mmc); return ret; }
int saveenv(void) { struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); if (init_mmc_for_env(mmc)) return 1; printf("Writing to MMC(%d)... ", CONFIG_SYS_MMC_ENV_DEV); if (write_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
/** * handles a client request */ static int write_request(stream_t *s, request_rec *r, config_t *config, int session_index, int backup_index) { int len; int code = -1; write_env(s, r); write_headers(s, r); write_added_headers(s, r); /* read post data */ if (ap_should_client_block(r)) { char buf[BUF_LENGTH]; int ack_size = s->cluster_srun->srun->send_buffer_size; int send_length = 0; while ((len = ap_get_client_block(r, buf, BUF_LENGTH)) > 0) { LOG(("%s:%d:write-request(): w-D %d\n", __FILE__, __LINE__, len)); if (ack_size <= send_length + len && send_length > 0) { LOG(("%s:%d:write-request(): w-Y send_length=%d ack_size=%d\n", __FILE__, __LINE__, send_length, ack_size)); send_length = 0; cse_write_byte(s, HMUX_YIELD); code = send_data(s, r); if (code != HMUX_ACK) break; } cse_write_packet(s, HMUX_DATA, buf, len); send_length += len; } } LOG(("%s:%d:write-request(): w-Q\n", __FILE__, __LINE__)); cse_write_byte(s, HMUX_QUIT); code = send_data(s, r); LOG(("%s:%d:write_request(): return code %c\n", __FILE__, __LINE__, code)); return code; }
int saveenv(void) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int mmc_env_devno = mmc_get_env_devno(); ssize_t len; char *res; struct mmc *mmc = find_mmc_device(mmc_env_devno); u32 offset; int ret; if (init_mmc_for_env(mmc)) return 1; if (mmc_get_env_addr(mmc, &offset)) { ret = 1; goto fini; } res = (char *)&env_new->data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); ret = 1; goto fini; } env_new->crc = crc32(0, &env_new->data[0], ENV_SIZE); printf("Writing to MMC(%d)... ", mmc_env_devno); if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) { puts("failed\n"); ret = 1; goto fini; } puts("done\n"); ret = 0; fini: fini_mmc_for_env(mmc); return ret; }
int system (const char *cmd) { int rc; char path [4096]; if (cmd == NULL) { errno = EINVAL; return (-1); } write_string (client_fd, cmd); write_string (client_fd, getcwd (path, sizeof (path))); write_env (client_fd); if (read (client_fd, &rc, sizeof (int)) < 0) { fprintf (stderr, "system: failed to read status from server: %s\n", strerror (errno)); return (-1); } return (rc); }
int saveenv(void) { block_dev_desc_t *sata = NULL; env_t env_new; ssize_t len; char *res; if (sata_curr_device == -1) { if (sata_initialize()) return 1; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return 1; } sata = sata_get_dev(sata_curr_device); res = (char *)&env_new.data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } env_new.crc = crc32(0, env_new.data, ENV_SIZE); printf("Writing to SATA(%d)...", sata_curr_device); if (write_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, &env_new)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
int saveenv(void) { env_t *env_new = (env_t *)env_buf; ssize_t len; char *res; res = (char *)env_new->data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return -1; } env_new->crc = crc32(0, env_new->data, ENV_SIZE); printf("Writing env to storage... \n"); if (write_env(CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, (u_char *)env_new)) { puts("failed\n"); return -1; } puts("done\n"); return 0; }
/*! \brief Remove name from environment Updates .gisrc \param name variable name */ void G_unsetenv(const char *name) { read_env(G_VAR_GISRC); unset_env(name, G_VAR_GISRC); write_env(G_VAR_GISRC); }
bool save_tune(const Tune& tune, const char* name, bool all) { FILE* f = fopen(name, "w"); if (!f) return false; if (all) { // timing fprintf(f, "ticks ="); write_env(f, tune.ticks_per_row); fprintf(f, "\nframes = %d\n", tune.frames_per_tick); // global stuff for (auto& p : tune.envs) { fprintf(f, "%-16s =", p.first.c_str()); write_env(f, p.second); fprintf(f, "\n"); } // macros for (auto& p : tune.macros) { fprintf(f, "MACRO %s", p.first.c_str()); auto& macro = p.second; if (!macro.parents.empty()) { fprintf(f, " <"); for (auto& p : macro.parents) fprintf(f, " %s", p.c_str()); } fprintf(f, "\n"); for (auto& p : macro.envs) { fprintf(f, " %-16s =", p.first.c_str()); write_env(f, p.second); fprintf(f, "\n"); } } } fprintf(f, "TABLE\n"); for (auto& line : tune.table) { int limit = line.size(); while (limit > 1 && line[limit - 1] == "") limit--; for (int c = 0; c < limit; c++) { fprintf(f, " "); fprintf(f, "%s", line[c].c_str()); for (int i = line[c].size(); i < PatternWin::CHAN_CHAR_WIDTH; i++) fprintf(f, "."); } fprintf(f, "\n"); } for (auto& p : tune.patterns) { fprintf(f, "PATTERN %s\n", p.first.c_str()); for (auto& row : p.second) { fprintf(f, " "); if (row.note > 0) { fprintf(f, "%c%c%X", "CCDDEFFGGAAB"[(row.note - 1) % 12], "-#-#--#-#-#-"[(row.note - 1) % 12], (row.note - 1) / 12); } else if (row.note == -1) fprintf(f, "==="); else fprintf(f, "..."); for (auto& m : row.macros) { fprintf(f, " %s", m.c_str()); for (int i = m.size(); i < PatternWin::MACRO_CHAR_WIDTH; i++) fprintf(f, "."); } fprintf(f, "\n"); } } fclose(f); return true; }
/*! \brief Set environment variable (updates .gisrc) If value is NULL, becomes an G_unsetenv(). \param name variable name \param value variable value */ void G_setenv(const char *name, const char *value) { read_env(G_VAR_GISRC); set_env(name, value, G_VAR_GISRC); write_env(G_VAR_GISRC); }
/*! \brief Set environment variable from specific place (updates .gisrc) If value is NULL, becomes an G_unsetenv(). \param name variable name \param value variable value \param loc location (G_VAR_GISRC, G_VAR_MAPSET) */ void G_setenv2(const char *name, const char *value, int loc) { read_env(loc); set_env(name, value, loc); write_env(loc); }
/*! \brief Remove name from environment from specific place Updates .gisrc \param name variable name \param loc location (G_VAR_GISRC, G_VAR_MAPSET) */ void G_unsetenv2(const char *name, int loc) { read_env(loc); unset_env(name, loc); write_env(loc); }
/*! \brief Writes current environment to .gisrc */ void G__write_env(void) { if (st->init[G_VAR_GISRC]) write_env(G_VAR_GISRC); }
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */ unsigned WINAPI SetPluginPath(void * pParam) { typedef int (__cdecl *_pwrite_env)(LPCWSTR envstring); int ret = 0; HMODULE hCrt =NULL; _pwrite_env write_env = NULL; char msvc_crt[CRT_LEN+1] = {0}; LPWSTR lpstring; if ( !find_msvcrt(msvc_crt,CRT_LEN) ) { return (0); } if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL ) { return (0); } if ( profile_path[1] != L':' ) { if (!ini_ready(profile_path,MAX_PATH)) { return (0); } } write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv"); if ( write_env == NULL ) { return (0); } if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) == NULL ) { return (0); } if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 ) { LPWSTR strKey = lpstring; while(*strKey != L'\0') { if ( stristrW(strKey, L"NpluginPath") ) { WCHAR lpfile[VALUE_LEN+1]; if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) ) { WCHAR env_string[VALUE_LEN+1] = {0}; PathToCombineW(lpfile, VALUE_LEN); if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0) { ret = write_env( (LPCWSTR)env_string ); } } } else if ( stristrW(strKey, L"VimpPentaHome") ) { WCHAR lpfile[VALUE_LEN+1]; if ( read_appkey(L"Env",L"VimpPentaHome",lpfile,sizeof(lpfile)) ) { WCHAR env_string[VALUE_LEN+1] = {0}; if (lpfile[1] != L':') { WCHAR vimp_path[VALUE_LEN+1] = {0}; charTochar(lpfile); if ( PathCombineW(vimp_path,portable_data_path,lpfile) ) { int n = _snwprintf(lpfile,VALUE_LEN,L"%ls",vimp_path); lpfile[n] = L'\0'; } } if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"HOME=",lpfile) > 0) { ret = write_env( (LPCWSTR)env_string ); } } } else if (stristrW(strKey, L"MOZ_GMP_PATH")) { WCHAR lpfile[VALUE_LEN+1]; if ( read_appkey(L"Env",L"MOZ_GMP_PATH",lpfile,sizeof(lpfile)) ) { WCHAR env_string[VALUE_LEN+1] = {0}; PathToCombineW(lpfile, VALUE_LEN); if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_GMP_PATH=",lpfile) > 0) { ret = write_env( (LPCWSTR)env_string ); } } } else if (stristrW(strKey, L"TmpDataPath")) { /* the PATH environment variable does not exist */ } else { ret = write_env( (LPCWSTR)strKey ); } strKey += wcslen(strKey)+1; } } SYS_FREE(lpstring); return (1); }
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */ unsigned WINAPI SetPluginPath(void * pParam) { typedef int (__cdecl *_pwrite_env)(LPCWSTR envstring); int ret = 0; HMODULE hCrt =NULL; _pwrite_env write_env = NULL; char msvc_crt[CRT_LEN+1] = {0}; LPWSTR lpstring; if ( !find_msvcrt(msvc_crt,CRT_LEN) ) { return ((unsigned)ret); } if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL ) { return ((unsigned)ret); } if ( profile_path[1] != L':' ) { if (!ini_ready(profile_path,MAX_PATH)) { return ((unsigned)ret); } } write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv"); if ( write_env ) { if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) != NULL ) { if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 ) { LPWSTR strKey = lpstring; while(*strKey != L'\0') { if ( stristrW(strKey, L"NpluginPath") ) { WCHAR lpfile[VALUE_LEN+1]; if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) ) { WCHAR env_string[VALUE_LEN+1] = {0}; PathToCombineW(lpfile, VALUE_LEN); if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0) { ret = write_env( (LPCWSTR)env_string ); } } } else if (stristrW(strKey, L"TmpDataPath")) { ; } else { ret = write_env( (LPCWSTR)strKey ); } strKey += wcslen(strKey)+1; } } SYS_FREE(lpstring); } } return ( (unsigned)ret ); }