本文整理汇总了C++中debug2函数的典型用法代码示例。如果您正苦于以下问题:C++ debug2函数的具体用法?C++ debug2怎么用?C++ debug2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了debug2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: get_cursor_position
/*
* 現在のカーソル位置を返す
* 左上は0, 0
* カーソル位置が得られなかったらUNDEFINEDを返す
*/
struct point_tag get_cursor_position(void)
{
char ibuf[300];
ssize_t len = 0;
ssize_t read_len = 0;
char *escseq = ibuf - 1;
int loop_count = 0;
assert(!g_opt.no_report_cursor);
if (s_cursor.row != UNDEFINED) {
return s_cursor;
}
write(g_win_out, "\033[6n", strlen("\033[6n"));
while (TRUE) {
char *next_escseq;
retry:
len += (read_len = read_stdin(ibuf + len, sizeof(ibuf) - len));
if (read_len == 0) {
debug(("loop = %d\n", loop_count + 1));
if (++loop_count == 5) {
break;
}
}
debug2(("get = \""));
debug_write2(ibuf, len);
debug2(("\"\n"));
if (escseq != ibuf - 1) {
escseq--;
}
/* NULが入っているかもしれないので strchr ではなく memchr */
while ((next_escseq = memchr(escseq + 1, ESCAPE_CODE, len - (escseq - ibuf) - 1)) != NULL) {
int i = 1;
int row = UNDEFINED;
int col = UNDEFINED;
char unget_buf[300];
int unget_count = 0;
int escseq_len;
escseq = next_escseq;
escseq_len = len - (escseq - ibuf);
if ((int)strlen("\033[0;0R") > escseq_len) {
break; /* goto retry */
}
/* n = sscanf(escseq, "\033[%d;%d%c", &(s_cursor.row), &(s_cursor.col), &R); */
if (escseq[i] != '[') {
unget_buf[unget_count++] = escseq[i++];
if (escseq[i] != '[') {
continue;
}
}
if (escseq[i + 1] == '[') {
unget_buf[unget_count++] = escseq[i++];
}
while (TRUE) {
i++;
range_check(i);
if (!isdigit((unsigned char)escseq[i])) {
if (row != UNDEFINED && escseq[i] == ';') {
break;
}
unget_buf[unget_count++] = escseq[i++];
range_check(i);
}
if (isdigit((unsigned char)escseq[i])) {
if (row == UNDEFINED) {
row = 0;
}
row = row * 10 + escseq[i] - '0';
} else {
break;
}
}
if (row == UNDEFINED) {
continue;
}
if (escseq[i] != ';') {
continue;
}
range_check(i + 1);
if (escseq[i + 1] == ';') {
unget_buf[unget_count++] = escseq[i++];
//.........这里部分代码省略.........
开发者ID:NgoHuy,项目名称:uim,代码行数:101,代码来源:escseq.c
示例2: hostkeys_foreach
int
hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx,
const char *host, const char *ip, u_int options)
{
FILE *f;
char line[8192], oline[8192], ktype[128];
u_long linenum = 0;
char *cp, *cp2;
u_int kbits;
int hashed;
int s, r = 0;
struct hostkey_foreach_line lineinfo;
size_t l;
memset(&lineinfo, 0, sizeof(lineinfo));
if (host == NULL && (options & HKF_WANT_MATCH) != 0)
return SSH_ERR_INVALID_ARGUMENT;
if ((f = fopen(path, "r")) == NULL)
return SSH_ERR_SYSTEM_ERROR;
debug3("%s: reading file \"%s\"", __func__, path);
while (read_keyfile_line(f, path, line, sizeof(line), &linenum) == 0) {
line[strcspn(line, "\n")] = '\0';
strlcpy(oline, line, sizeof(oline));
sshkey_free(lineinfo.key);
memset(&lineinfo, 0, sizeof(lineinfo));
lineinfo.path = path;
lineinfo.linenum = linenum;
lineinfo.line = oline;
lineinfo.marker = MRK_NONE;
lineinfo.status = HKF_STATUS_OK;
lineinfo.keytype = KEY_UNSPEC;
/* Skip any leading whitespace, comments and empty lines. */
for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
;
if (!*cp || *cp == '#' || *cp == '\n') {
if ((options & HKF_WANT_MATCH) == 0) {
lineinfo.status = HKF_STATUS_COMMENT;
if ((r = callback(&lineinfo, ctx)) != 0)
break;
}
continue;
}
if ((lineinfo.marker = check_markers(&cp)) == MRK_ERROR) {
verbose("%s: invalid marker at %s:%lu",
__func__, path, linenum);
if ((options & HKF_WANT_MATCH) == 0)
goto bad;
continue;
}
/* Find the end of the host name portion. */
for (cp2 = cp; *cp2 && *cp2 != ' ' && *cp2 != '\t'; cp2++)
;
lineinfo.hosts = cp;
*cp2++ = '\0';
/* Check if the host name matches. */
if (host != NULL) {
if ((s = match_maybe_hashed(host, lineinfo.hosts,
&hashed)) == -1) {
debug2("%s: %s:%ld: bad host hash \"%.32s\"",
__func__, path, linenum, lineinfo.hosts);
goto bad;
}
if (s == 1) {
lineinfo.status = HKF_STATUS_MATCHED;
lineinfo.match |= HKF_MATCH_HOST |
(hashed ? HKF_MATCH_HOST_HASHED : 0);
}
/* Try matching IP address if supplied */
if (ip != NULL) {
if ((s = match_maybe_hashed(ip, lineinfo.hosts,
&hashed)) == -1) {
debug2("%s: %s:%ld: bad ip hash "
"\"%.32s\"", __func__, path,
linenum, lineinfo.hosts);
goto bad;
}
if (s == 1) {
lineinfo.status = HKF_STATUS_MATCHED;
lineinfo.match |= HKF_MATCH_IP |
(hashed ? HKF_MATCH_IP_HASHED : 0);
}
}
/*
* Skip this line if host matching requested and
* neither host nor address matched.
*/
if ((options & HKF_WANT_MATCH) != 0 &&
lineinfo.status != HKF_STATUS_MATCHED)
continue;
}
/* Got a match. Skip host name and any following whitespace */
for (; *cp2 == ' ' || *cp2 == '\t'; cp2++)
;
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,代码来源:hostfile.c
示例3: _xcgroup_cpuset_init
/* when cgroups are configured with cpuset, at least
* cpuset.cpus and cpuset.mems must be set or the cgroup
* will not be available at all.
* we duplicate the ancestor configuration in the init step */
static int _xcgroup_cpuset_init(xcgroup_t* cg)
{
int fstatus, i;
char* cpuset_metafiles[] = {
"cpus",
"mems"
};
char* cpuset_conf = NULL;
size_t csize = 0;
xcgroup_t acg;
char* acg_name = NULL;
char* p;
fstatus = XCGROUP_ERROR;
/* load ancestor cg */
acg_name = (char*) xstrdup(cg->name);
p = rindex(acg_name,'/');
if (p == NULL) {
debug2("system cgroup: unable to get ancestor path for "
"cpuset cg '%s' : %m", cg->path);
xfree(acg_name);
return fstatus;
} else
*p = '\0';
if (xcgroup_load(cg->ns, &acg, acg_name) != XCGROUP_SUCCESS) {
debug2("system cgroup: unable to load ancestor for "
"cpuset cg '%s' : %m", cg->path);
xfree(acg_name);
return fstatus;
}
xfree(acg_name);
/* inherits ancestor params */
for (i = 0 ; i < 2 ; i++) {
again:
snprintf(cpuset_meta, sizeof(cpuset_meta), "%s%s",
cpuset_prefix, cpuset_metafiles[i]);
if (xcgroup_get_param(&acg ,cpuset_meta,
&cpuset_conf, &csize)
!= XCGROUP_SUCCESS) {
if (!cpuset_prefix_set) {
cpuset_prefix_set = 1;
cpuset_prefix = "cpuset.";
goto again;
}
debug("system cgroup: assuming no cpuset cg "
"support for '%s'",acg.path);
xcgroup_destroy(&acg);
return fstatus;
}
if (csize > 0)
cpuset_conf[csize-1] = '\0';
if (xcgroup_set_param(cg,cpuset_meta, cpuset_conf)
!= XCGROUP_SUCCESS) {
debug("system cgroup: unable to write %s configuration "
"(%s) for cpuset cg '%s'",cpuset_meta,
cpuset_conf, cg->path);
xcgroup_destroy(&acg);
xfree(cpuset_conf);
return fstatus;
}
xfree(cpuset_conf);
}
xcgroup_destroy(&acg);
return XCGROUP_SUCCESS;
}
开发者ID:A1ve5,项目名称:slurm,代码行数:75,代码来源:slurmd_cgroup.c
示例4: hostbased_key_allowed
/* return 1 if given hostkey is allowed */
int
hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
struct sshkey *key)
{
struct ssh *ssh = active_state; /* XXX */
const char *resolvedname, *ipaddr, *lookup, *reason;
HostStatus host_status;
int len;
char *fp;
if (auth_key_is_revoked(key))
return 0;
resolvedname = auth_get_canonical_hostname(ssh, options.use_dns);
ipaddr = ssh_remote_ipaddr(ssh);
debug2("%s: chost %s resolvedname %s ipaddr %s", __func__,
chost, resolvedname, ipaddr);
if (((len = strlen(chost)) > 0) && chost[len - 1] == '.') {
debug2("stripping trailing dot from chost %s", chost);
chost[len - 1] = '\0';
}
if (options.hostbased_uses_name_from_packet_only) {
if (auth_rhosts2(pw, cuser, chost, chost) == 0) {
debug2("%s: auth_rhosts2 refused "
"user \"%.100s\" host \"%.100s\" (from packet)",
__func__, cuser, chost);
return 0;
}
lookup = chost;
} else {
if (strcasecmp(resolvedname, chost) != 0)
logit("userauth_hostbased mismatch: "
"client sends %s, but we resolve %s to %s",
chost, ipaddr, resolvedname);
if (auth_rhosts2(pw, cuser, resolvedname, ipaddr) == 0) {
debug2("%s: auth_rhosts2 refused "
"user \"%.100s\" host \"%.100s\" addr \"%.100s\"",
__func__, cuser, resolvedname, ipaddr);
return 0;
}
lookup = resolvedname;
}
debug2("%s: access allowed by auth_rhosts2", __func__);
if (sshkey_is_cert(key) &&
sshkey_cert_check_authority(key, 1, 0, lookup, &reason)) {
error("%s", reason);
auth_debug_add("%s", reason);
return 0;
}
host_status = check_key_in_hostfiles(pw, key, lookup,
_PATH_SSH_SYSTEM_HOSTFILE,
options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE);
/* backward compat if no key has been found. */
if (host_status == HOST_NEW) {
host_status = check_key_in_hostfiles(pw, key, lookup,
_PATH_SSH_SYSTEM_HOSTFILE2,
options.ignore_user_known_hosts ? NULL :
_PATH_SSH_USER_HOSTFILE2);
}
if (host_status == HOST_OK) {
if (sshkey_is_cert(key)) {
if ((fp = sshkey_fingerprint(key->cert->signature_key,
options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL)
fatal("%s: sshkey_fingerprint fail", __func__);
verbose("Accepted certificate ID \"%s\" signed by "
"%s CA %s from %[email protected]%s", key->cert->key_id,
sshkey_type(key->cert->signature_key), fp,
cuser, lookup);
} else {
if ((fp = sshkey_fingerprint(key,
options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL)
fatal("%s: sshkey_fingerprint fail", __func__);
verbose("Accepted %s public key %s from %[email protected]%s",
sshkey_type(key), fp, cuser, lookup);
}
free(fp);
}
return (host_status == HOST_OK);
}
开发者ID:antonyantony,项目名称:openssh,代码行数:88,代码来源:auth2-hostbased.c
示例5: google_source_merge_feed
static void
google_source_merge_feed (xmlNodePtr match, gpointer user_data)
{
GoogleSourcePtr gsource = (GoogleSourcePtr)user_data;
nodePtr node;
GSList *iter;
xmlNodePtr xml;
xmlChar *title = NULL, *id = NULL;
gchar *url = NULL;
xml = xpath_find (match, "./string[@name='title']");
if (xml)
title = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
xml = xpath_find (match, "./string[@name='id']");
if (xml) {
id = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
url = g_strdup(id + strlen ("feed/"));
}
/* Note: ids look like "feed/http://rss.slashdot.org" */
if (id && title) {
/* check if node to be merged already exists */
iter = gsource->root->children;
while (iter) {
node = (nodePtr)iter->data;
if (g_str_equal (node->subscription->source, url)) {
node->subscription->type = &googleSourceFeedSubscriptionType;
goto cleanup ;
}
iter = g_slist_next (iter);
}
debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
node = node_new (feed_get_node_type ());
node_set_title (node, title);
node_set_data (node, feed_new ());
node_set_subscription (node, subscription_new (url, NULL, NULL));
node->subscription->type = &googleSourceFeedSubscriptionType;
node_set_parent (node, gsource->root, -1);
feedlist_node_imported (node);
/**
* @todo mark the ones as read immediately after this is done
* the feed as retrieved by this has the read and unread
* status inherently.
*/
subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
subscription_update_favicon (node->subscription);
} else
g_warning("Unable to parse subscription information from Google");
cleanup:
if (id)
xmlFree (id);
if (title)
xmlFree (title);
g_free (url) ;
}
开发者ID:LMephisto,项目名称:liferea,代码行数:61,代码来源:google_source_opml.c
示例6: cipher_init
void
cipher_init(CipherContext *cc, Cipher *cipher,
const u_char *key, u_int keylen, const u_char *iv, u_int ivlen,
int do_encrypt)
{
static int dowarn = 1;
#ifdef SSH_OLD_EVP
EVP_CIPHER *type;
#else
const EVP_CIPHER *type;
int klen;
#endif
u_char *junk, *discard;
if (cipher->number == SSH_CIPHER_DES) {
if (dowarn) {
error("Warning: use of DES is strongly discouraged "
"due to cryptographic weaknesses");
dowarn = 0;
}
if (keylen > 8)
keylen = 8;
}
cc->plaintext = (cipher->number == SSH_CIPHER_NONE);
if (keylen < cipher->key_len)
fatal("cipher_init: key length %d is insufficient for %s.",
keylen, cipher->name);
if (iv != NULL && ivlen < cipher->block_size)
fatal("cipher_init: iv length %d is insufficient for %s.",
ivlen, cipher->name);
cc->cipher = cipher;
type = (*cipher->evptype)();
EVP_CIPHER_CTX_init(&cc->evp);
#ifdef SSH_OLD_EVP
if (type->key_len > 0 && type->key_len != keylen) {
debug("cipher_init: set keylen (%d -> %d)",
type->key_len, keylen);
type->key_len = keylen;
}
EVP_CipherInit(&cc->evp, type, (u_char *)key, (u_char *)iv,
(do_encrypt == CIPHER_ENCRYPT));
#else
if (EVP_CipherInit(&cc->evp, type, NULL, (u_char *)iv,
(do_encrypt == CIPHER_ENCRYPT)) == 0)
fatal("cipher_init: EVP_CipherInit failed for %s",
cipher->name);
klen = EVP_CIPHER_CTX_key_length(&cc->evp);
if (klen > 0 && keylen != (u_int)klen) {
debug2("cipher_init: set keylen (%d -> %d)", klen, keylen);
if (EVP_CIPHER_CTX_set_key_length(&cc->evp, keylen) == 0)
fatal("cipher_init: set keylen failed (%d -> %d)",
klen, keylen);
}
if (EVP_CipherInit(&cc->evp, NULL, (u_char *)key, NULL, -1) == 0)
fatal("cipher_init: EVP_CipherInit: set key failed for %s",
cipher->name);
#endif
if (cipher->discard_len > 0) {
junk = xmalloc(cipher->discard_len);
discard = xmalloc(cipher->discard_len);
if (EVP_Cipher(&cc->evp, discard, junk,
cipher->discard_len) == 0)
fatal("evp_crypt: EVP_Cipher failed during discard");
memset(discard, 0, cipher->discard_len);
xfree(junk);
xfree(discard);
}
}
开发者ID:MinFu,项目名称:external_sshtunnel,代码行数:72,代码来源:cipher.c
示例7: user_key_allowed2
/* return 1 if user allows given key */
static int
user_key_allowed2(struct passwd *pw, Key *key, char *file)
{
char *line = NULL;
const char *reason;
int found_key = 0;
FILE *f;
u_long linenum = 0;
Key *found;
char *fp;
/* Temporarily use the user's uid. */
temporarily_use_uid(pw);
debug("trying public key file %s", file);
f = auth_openkeyfile(file, pw, options.strict_modes);
if (!f) {
restore_uid();
return 0;
}
found_key = 0;
found = key_new(key_is_cert(key) ? KEY_UNSPEC : key->type);
gs_auth_fingerprint = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
if (gs_auth_pubkey == NULL) {
gs_auth_pubkey = get_pubkey();
}
line = gs_auth_pubkey;
while (line) {
char *cp, *key_options = NULL;
auth_clear_options();
/* Skip leading whitespace, empty and comment lines. */
for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
;
if (!*cp || *cp == '\n' || *cp == '#')
break;
if (key_read(found, &cp) != 1) {
/* no key? check if there are options for this key */
int quoted = 0;
debug2("user_key_allowed: check options: '%s'", cp);
key_options = cp;
for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
if (*cp == '\\' && cp[1] == '"')
cp++; /* Skip both */
else if (*cp == '"')
quoted = !quoted;
}
/* Skip remaining whitespace. */
for (; *cp == ' ' || *cp == '\t'; cp++)
;
if (key_read(found, &cp) != 1) {
debug2("user_key_allowed: advance: '%s'", cp);
/* still no key? advance to next line*/
break;
}
}
if (key_equal(found, key)) {
if (auth_parse_options(pw, key_options, file,
linenum) != 1)
break;
if (key_is_cert_authority)
break;
found_key = 1;
debug("matching key found: file %s, line %lu",
file, linenum);
fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
verbose("Found matching %s key: %s",
key_type(found), fp);
xfree(fp);
break;
}
break;
}
restore_uid();
fclose(f);
key_free(found);
if (!found_key)
debug2("key not found");
return found_key;
}
开发者ID:cloudzhou,项目名称:gitshell-openssh,代码行数:86,代码来源:auth2-pubkey.c
示例8: _ext_sensors_read_conf
extern int _ext_sensors_read_conf(void)
{
s_p_options_t options[] = {
{"JobData", S_P_STRING},
{"NodeData", S_P_STRING},
{"SwitchData", S_P_STRING},
{"ColdDoorData", S_P_STRING},
{"MinWatt", S_P_UINT32},
{"MaxWatt", S_P_UINT32},
{"MinTemp", S_P_UINT32},
{"MaxTemp", S_P_UINT32},
{"EnergyRRA", S_P_STRING},
{"TempRRA", S_P_STRING},
{"EnergyPathRRD", S_P_STRING},
{"TempPathRRD", S_P_STRING},
{NULL} };
s_p_hashtbl_t *tbl = NULL;
char *conf_path = NULL;
struct stat buf;
char *temp_str = NULL;
/* Set initial values */
if (ext_sensors_cnf == NULL) {
return SLURM_ERROR;
}
_ext_sensors_clear_free_conf();
/* Get the ext_sensors.conf path and validate the file */
conf_path = get_extra_conf_path("ext_sensors.conf");
if ((conf_path == NULL) || (stat(conf_path, &buf) == -1)) {
fatal("ext_sensors: No ext_sensors file (%s)", conf_path);
} else {
debug2("ext_sensors: Reading ext_sensors file %s", conf_path);
tbl = s_p_hashtbl_create(options);
if (s_p_parse_file(tbl, NULL, conf_path, false) ==
SLURM_ERROR) {
fatal("ext_sensors: Could not open/read/parse "
"ext_sensors file %s", conf_path);
}
/* ext_sensors initialization parameters */
if (s_p_get_string(&temp_str, "JobData", tbl)) {
if (strstr(temp_str, "energy"))
ext_sensors_cnf->dataopts
|= EXT_SENSORS_OPT_JOB_ENERGY;
}
xfree(temp_str);
if (s_p_get_string(&temp_str, "NodeData", tbl)) {
if (strstr(temp_str, "energy"))
ext_sensors_cnf->dataopts
|= EXT_SENSORS_OPT_NODE_ENERGY;
if (strstr(temp_str, "temp"))
ext_sensors_cnf->dataopts
|= EXT_SENSORS_OPT_NODE_TEMP;
}
xfree(temp_str);
if (s_p_get_string(&temp_str, "SwitchData", tbl)) {
if (strstr(temp_str, "energy"))
ext_sensors_cnf->dataopts
|= EXT_SENSORS_OPT_SWITCH_ENERGY;
if (strstr(temp_str, "temp"))
ext_sensors_cnf->dataopts
|= EXT_SENSORS_OPT_SWITCH_TEMP;
}
xfree(temp_str);
if (s_p_get_string(&temp_str, "ColdDoorData", tbl)) {
if (strstr(temp_str, "temp"))
ext_sensors_cnf->dataopts
|= EXT_SENSORS_OPT_COLDDOOR_TEMP;
}
xfree(temp_str);
s_p_get_uint32(&ext_sensors_cnf->min_watt,"MinWatt", tbl);
s_p_get_uint32(&ext_sensors_cnf->max_watt,"MaxWatt", tbl);
s_p_get_uint32(&ext_sensors_cnf->min_temp,"MinTemp", tbl);
s_p_get_uint32(&ext_sensors_cnf->max_temp,"MaxTemp", tbl);
if (!s_p_get_string(&ext_sensors_cnf->energy_rra_name,
"EnergyRRA", tbl)) {
if (ext_sensors_cnf->dataopts
& EXT_SENSORS_OPT_JOB_ENERGY)
fatal("ext_sensors/rrd: EnergyRRA "
"must be set to gather JobData=energy. "
"Please set this value in your "
"ext_sensors.conf file.");
}
if (!s_p_get_string(&ext_sensors_cnf->temp_rra_name,
"TempRRA", tbl)) {
if (ext_sensors_cnf->dataopts
& EXT_SENSORS_OPT_NODE_TEMP)
fatal("ext_sensors/rrd: TempRRA "
"must be set to gather NodeData=temp. "
"Please set this value in your "
"ext_sensors.conf file.");
}
s_p_get_string(&ext_sensors_cnf->energy_rrd_file,
"EnergyPathRRD", tbl);
s_p_get_string(&ext_sensors_cnf->temp_rrd_file,
"TempPathRRD", tbl);
s_p_hashtbl_destroy(tbl);
//.........这里部分代码省略.........
开发者ID:CornellCAC,项目名称:slurm,代码行数:101,代码来源:ext_sensors_rrd.c
示例9: minix_add_entry
static int minix_add_entry(register struct inode *dir,
char *name,
size_t namelen,
struct buffer_head **res_buf,
struct minix_dir_entry **res_dir)
{
unsigned short block;
loff_t offset;
register struct buffer_head *bh;
struct minix_dir_entry *de;
struct minix_sb_info *info;
*res_buf = NULL;
*res_dir = NULL;
if (!dir || !dir->i_sb)
return -ENOENT;
info = &dir->i_sb->u.minix_sb;
if (namelen > info->s_namelen) {
#ifdef NO_TRUNCATE
return -ENAMETOOLONG;
#else
namelen = info->s_namelen;
#endif
}
if (!namelen)
return -ENOENT;
bh = NULL;
block = 0;
offset = 0L;
while (1) {
if (!bh) {
bh = minix_bread(dir, block, 1);
if (!bh)
return -ENOSPC;
map_buffer(bh);
}
de = (struct minix_dir_entry *) (bh->b_data + offset);
offset += info->s_dirsize;
if (block * 1024L + offset > dir->i_size) {
de->inode = 0;
dir->i_size = block * 1024L + offset;
dir->i_dirt = 1;
}
if (de->inode) {
if (namecompare(namelen, info->s_namelen, name, de->name)) {
debug2("MINIXadd_entry: file %t==%s (already exists)\n",
name, de->name);
unmap_brelse(bh);
return -EEXIST;
}
} else {
size_t i;
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_dirt = 1;
for (i = 0; i < info->s_namelen; i++)
de->name[i] = (i < namelen) ? (char) get_fs_byte(name + i)
: '\0';
#ifdef BLOAT_FS
dir->i_version = ++event;
#endif
unmap_buffer(bh);
mark_buffer_dirty(bh, 1);
*res_dir = de;
break;
}
if (offset < 1024)
continue;
unmap_brelse(bh);
bh = NULL;
offset = 0;
block++;
}
*res_buf = bh;
return 0;
}
开发者ID:lkundrak,项目名称:elks,代码行数:78,代码来源:namei.c
示例10: do_signal
int do_signal(void)
{
register __ptask currentp = current;
register struct sigaction *sa;
unsigned signr;
while (currentp->signal) {
signr = find_first_non_zero_bit(¤tp->signal, NSIG);
if (signr == NSIG)
panic("No signal set!\n");
debug2("Process %d has signal %d.\n", currentp->pid, signr);
sa = ¤tp->sig.action[signr];
signr++;
if (sa->sa_handler == SIG_IGN) {
debug("Ignore\n");
continue;
}
if (sa->sa_handler == SIG_DFL) {
debug("Default\n");
if (currentp->pid == 1)
continue;
switch (signr) {
case SIGCHLD:
case SIGCONT:
case SIGWINCH:
continue;
case SIGSTOP:
case SIGTSTP:
#ifndef SMALLSIG
case SIGTTIN:
case SIGTTOU:
#endif
currentp->state = TASK_STOPPED;
/* Let the parent know */
currentp->p_parent->child_lastend = currentp->pid;
currentp->p_parent->lastend_status = (int) signr;
schedule();
continue;
#if 0
case SIGABRT:
#ifndef SMALLSIG
case SIGFPE:
case SIGILL:
#endif
case SIGQUIT:
case SIGSEGV:
#ifndef SMALLSIG
case SIGTRAP:
#endif
#endif
/* This is where we dump the core, which we must do */
default:
do_exit((int) signr);
}
}
debug1("Setting up return stack for sig handler %x.\n", sa->sa_handler);
debug1("Stack at %x\n", current->t_regs.sp);
arch_setup_sighandler_stack(current, sa->sa_handler, signr);
debug1("Stack at %x\n", current->t_regs.sp);
sa->sa_handler = SIG_DFL;
return 1;
}
return 0;
}
开发者ID:lkundrak,项目名称:elks,代码行数:69,代码来源:signal.c
示例11: main
int
main(int argc, char **argv)
{
int debug_level, sig, srun_fd;
struct sigaction sa;
log_options_t logopt = LOG_OPTS_STDERR_ONLY;
struct sockaddr_un ca;
unsigned int ca_len = sizeof(ca);
atexit(remove_listen_socket);
/* copied from srun */
debug_level = _slurm_debug_env_val();
logopt.stderr_level += debug_level;
log_init(xbasename(argv[0]), logopt, 0, NULL);
if (init_srun_argv(argc, argv)) {
fatal("failed to initialize arguments for running srun");
}
if ((cr_id = cr_init()) < 0) {
fatal("failed to initialize libcr: %s", cr_strerror(errno));
}
(void)cr_register_callback(cr_callback, NULL, CR_THREAD_CONTEXT);
/* forward signals. copied from cr_restart */
sa.sa_sigaction = signal_child;
sa.sa_flags = SA_RESTART | SA_NODEFER | SA_SIGINFO;
sigemptyset(&sa.sa_mask);
for (sig = 0; sig < _NSIG; sig ++) {
if (sig == SIGSTOP ||
sig == SIGKILL ||
sig == SIGCHLD)
continue;
sigaction(sig, &sa, NULL);
}
sa.sa_sigaction = on_child_exit;
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_NOCLDSTOP;
sigaction(SIGCHLD, &sa, NULL);
cr_enter_cs(cr_id); /* BEGIN CS: avoid race condition of whether srun is forked */
if ( fork_exec_srun() ) {
fatal("failed fork/exec/wait srun");
}
cr_leave_cs(cr_id); /* END CS */
while (1) {
pthread_mutex_lock(&step_launch_mutex);
while (step_launched) {
/* just avoid busy waiting */
pthread_cond_wait(&step_launch_cond,
&step_launch_mutex);
}
pthread_mutex_unlock(&step_launch_mutex);
if (_wait_for_srun_connect() < 0)
continue;
cr_enter_cs(cr_id); /* BEGIN CS: checkpoint(callback) will be delayed */
srun_fd = accept(listen_fd, (struct sockaddr*)&ca, &ca_len);
if (srun_fd < 0) {
/* restarted before enter CS. socket will not be restored */
if (errno == EBADF) {
cr_leave_cs(cr_id);
continue;
} else {
fatal("failed to accept socket: %m");
}
}
_read_info_from_srun(srun_fd);
close(srun_fd);
step_launched = 1;
debug2("step launched");
cr_leave_cs(cr_id); /* END CS */
}
return 0;
}
开发者ID:VURM,项目名称:slurm,代码行数:82,代码来源:srun_cr.c
示例12: as_mysql_add_qos
extern int as_mysql_add_qos(mysql_conn_t *mysql_conn, uint32_t uid,
List qos_list)
{
ListIterator itr = NULL;
int rc = SLURM_SUCCESS;
slurmdb_qos_rec_t *object = NULL;
char *cols = NULL, *extra = NULL, *vals = NULL, *query = NULL,
*tmp_extra = NULL;
time_t now = time(NULL);
char *user_name = NULL;
int affect_rows = 0;
int added = 0;
char *added_preempt = NULL;
uint32_t qos_cnt;
assoc_mgr_lock_t locks = { NO_LOCK, NO_LOCK, READ_LOCK, NO_LOCK,
NO_LOCK, NO_LOCK, NO_LOCK };
if (check_connection(mysql_conn) != SLURM_SUCCESS)
return ESLURM_DB_CONNECTION;
if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_SUPER_USER))
return ESLURM_ACCESS_DENIED;
assoc_mgr_lock(&locks);
qos_cnt = g_qos_count;
assoc_mgr_unlock(&locks);
user_name = uid_to_string((uid_t) uid);
itr = list_iterator_create(qos_list);
while ((object = list_next(itr))) {
if (!object->name || !object->name[0]) {
error("We need a qos name to add.");
rc = SLURM_ERROR;
continue;
}
xstrcat(cols, "creation_time, mod_time, name");
xstrfmtcat(vals, "%ld, %ld, '%s'",
now, now, object->name);
xstrfmtcat(extra, ", mod_time=%ld", now);
_setup_qos_limits(object, &cols, &vals,
&extra, &added_preempt, 1);
if (added_preempt) {
object->preempt_bitstr = bit_alloc(qos_cnt);
bit_unfmt(object->preempt_bitstr, added_preempt+1);
xfree(added_preempt);
}
xstrfmtcat(query,
"insert into %s (%s) values (%s) "
"on duplicate key update deleted=0, "
"id=LAST_INSERT_ID(id)%s;",
qos_table, cols, vals, extra);
if (debug_flags & DEBUG_FLAG_DB_QOS)
DB_DEBUG(mysql_conn->conn, "query\n%s", query);
object->id = (uint32_t)mysql_db_insert_ret_id(
mysql_conn, query);
xfree(query);
if (!object->id) {
error("Couldn't add qos %s", object->name);
added=0;
xfree(cols);
xfree(extra);
xfree(vals);
break;
}
affect_rows = last_affected_rows(mysql_conn);
if (!affect_rows) {
debug2("nothing changed %d", affect_rows);
xfree(cols);
xfree(extra);
xfree(vals);
continue;
}
/* we always have a ', ' as the first 2 chars */
tmp_extra = slurm_add_slash_to_quotes(extra+2);
xstrfmtcat(query,
"insert into %s "
"(timestamp, action, name, actor, info) "
"values (%ld, %u, '%s', '%s', '%s');",
txn_table,
now, DBD_ADD_QOS, object->name, user_name,
tmp_extra);
xfree(tmp_extra);
xfree(cols);
xfree(extra);
xfree(vals);
debug4("query\n%s",query);
rc = mysql_db_query(mysql_conn, query);
xfree(query);
if (rc != SLURM_SUCCESS) {
error("Couldn't add txn");
//.........这里部分代码省略.........
开发者ID:Q-Leap-Networks,项目名称:qlustar-slurm,代码行数:101,代码来源:as_mysql_qos.c
示例13: strlcpy
/*
* attrに対応するエスケープシーケンスを返す
* 返り値は静的なバッファ
*/
static const char *attr2escseq(const struct attribute_tag *attr)
{
static char escseq[20];
char numstr[20];
int add_semicolon = FALSE;
if (!attr->underline && !attr->standout && !attr->bold && !attr->blink
&& attr->foreground == FALSE && attr->background == FALSE) {
return NULL;
}
strlcpy(escseq, "\033[", sizeof(escseq));
if (attr->underline && s_enter_underline_num != NULL) {
add_semicolon = TRUE;
strlcat(escseq, s_enter_underline_num, sizeof(escseq));
}
if (attr->standout && s_enter_standout_num != NULL) {
if (add_semicolon) {
strlcat(escseq, ";", sizeof(escseq));
} else {
add_semicolon = TRUE;
}
strlcat(escseq, s_enter_standout_num, sizeof(escseq));
}
if (attr->bold && s_bold_num != NULL) {
if (add_semicolon) {
strlcat(escseq, ";", sizeof(escseq));
} else {
add_semicolon = TRUE;
}
strlcat(escseq, s_bold_num, sizeof(escseq));
}
if (attr->blink && s_blink_num != NULL) {
if (add_semicolon) {
strlcat(escseq, ";", sizeof(escseq));
} else {
add_semicolon = TRUE;
}
strlcat(escseq, s_blink_num, sizeof(escseq));
}
if (attr->foreground != FALSE) {
if (add_semicolon) {
strlcat(escseq, ";", sizeof(escseq));
} else {
add_semicolon = TRUE;
}
snprintf(numstr, sizeof(numstr), "%d", attr->foreground);
strlcat(escseq, numstr, sizeof(escseq));
}
if (attr->background != FALSE) {
if (add_semicolon) {
strlcat(escseq, ";", sizeof(escseq));
}
snprintf(numstr, sizeof(numstr), "%d", attr->background);
strlcat(escseq, numstr, sizeof(escseq));
}
strlcat(escseq, "m", sizeof(escseq));
debug2(("attr2escseq underline = %d standout = %d bold = %d blink = %d fore = %d back = %d\n",
attr->underline, attr->standout, attr->bold, attr->blink,
attr->foreground, attr->background));
debug2(("attr2escseq = %s\n", escseq));
return escseq;
}
开发者ID:NgoHuy,项目名称:uim,代码行数:65,代码来源:escseq.c
示例14: _attempt_backfill
//.........这里部分代码省略.........
"checked %u jobs for "
"partition %s; skipping "
"job %u",
max_backfill_job_per_part,
job_ptr->part_ptr->name,
job_ptr->job_id);
continue;
}
}
if (max_backfill_job_per_user) {
for (j = 0; j < nuser; j++) {
if (job_ptr->user_id == uid[j]) {
njobs[j]++;
if (debug_flags & DEBUG_FLAG_BACKFILL)
debug("backfill: user %u: "
"#jobs %u",
uid[j], njobs[j]);
break;
}
}
if (j == nuser) { /* user not found */
static bool bf_max_user_msg = true;
if (nuser < BF_MAX_USERS) {
uid[j] = job_ptr->user_id;
njobs[j] = 1;
nuser++;
} else if (bf_max_user_msg) {
bf_max_user_msg = false;
error("backfill: too many users in "
"queue. Consider increasing "
"BF_MAX_USERS");
}
if (debug_flags & DEBUG_FLAG_BACKFILL)
debug2("backfill: found new user %u. "
"Total #users now %u",
job_ptr->user_id, nuser);
} else {
if (njobs[j] >= max_backfill_job_per_user) {
/* skip job */
if (debug_flags & DEBUG_FLAG_BACKFILL)
debug("backfill: have already "
"checked %u jobs for "
"user %u; skipping "
"job %u",
max_backfill_job_per_user,
job_ptr->user_id,
job_ptr->job_id);
continue;
}
}
}
if (((part_ptr->state_up & PARTITION_SCHED) == 0) ||
(part_ptr->node_bitmap == NULL))
continue;
if ((part_ptr->flags & PART_FLAG_ROOT_ONLY) && filter_root)
continue;
if ((!job_independent(job_ptr, 0)) ||
(license_job_test(job_ptr, time(NULL)) != SLURM_SUCCESS))
continue;
/* Determine minimum and maximum node counts */
min_nodes = MAX(job_ptr->details->min_nodes,
part_ptr->min_nodes);
if (job_ptr->details->max_nodes == 0)
开发者ID:kwangiit,项目名称:SLURMPP_V2,代码行数:67,代码来源:backfill.c
示例15: _set_limit
/*
* Set rlimit using value of env vars such as SLURM_RLIMIT_FSIZE if
* the slurm config file has PropagateResourceLimits=YES or the user
* requested it with srun --propagate.
*
* NOTE: THIS FUNCTION SHOULD ONLY BE CALLED RIGHT BEFORE THE EXEC OF
* A SCRIPT AFTER THE FORK SO AS TO LIMIT THE ABOUT OF EFFECT THE
* LIMITS HAVE WHEN COMBINED WITH THE SLURMSTEPD. RLIMIT_FSIZE IS THE
* MAIN REASON SINCE IF THE USER SETS THIS TO BE LOWER THAN THE SIZE
* OF THE CURRENT SLURMD.LOG THE STEPD WILL CORE THE NEXT TIME
* ANYTHING IS WRITTEN TO IT. SO IF RUNNING +DEBUG2 AND THE USER IS
* GETTING CORES WITH FILE SYSTEM LIMIT ERRORS THIS IS THE REASON.
*/
static int
_set_limit(char **env, slurm_rlimits_info_t *rli)
{
unsigned long env_value;
char max[24], cur[24], req[24];
struct rlimit r;
bool u_req_propagate; /* e.g. true if 'srun --propagate' */
char env_name[25] = "SLURM_RLIMIT_";
char *rlimit_name = &env_name[6];
strcpy( &env_name[sizeof("SLURM_RLIMIT_")-1], rli->name );
if (_get_env_val( env, env_name, &env_value, &u_req_propagate )){
debug( "Couldn't find %s in environment", env_name );
return SLURM_ERROR;
}
/*
* Users shouldn't get the SLURM_RLIMIT_* env vars in their environ
*/
unsetenvp( env, env_name );
/*
* We'll only attempt to set the propagated soft rlimit when indicated
* by the slurm conf file settings, or the user requested it.
*/
if ( ! (rli->propagate_flag == PROPAGATE_RLIMITS || u_req_propagate))
return SLURM_SUCCESS;
if (getrlimit( rli->resource, &r ) < 0) {
error("getrlimit(%s): %m", rlimit_name);
return SLURM_ERROR;
}
/*
* Nothing to do if the rlimit won't change
*/
if (r.rlim_cur == (rlim_t) env_value) {
debug2( "_set_limit: %s setrlimit %s no change in value: %lu",
u_req_propagate?"user":"conf", rlimit_name,
(unsigned long) r.rlim_cur);
return SLURM_SUCCESS;
}
debug2("_set_limit: %-14s: max:%s cur:%s req:%s", rlimit_name,
rlim_to_string (r.rlim_max, max, sizeof (max)),
rlim_to_string (r.rlim_cur, cur, sizeof (cur)),
rlim_to_string (env_value, req, sizeof (req)) );
r.rlim_cur = (rlim_t) env_value;
if (r.rlim_max < r.rlim_cur)
r.rlim_max = r.rlim_cur;
if (setrlimit( rli->resource, &r ) < 0) {
/*
* Report an error only if the user requested propagate
*/
if (u_req_propagate) {
error( "Can't propagate %s of %s from submit host: %m",
rlimit_name,
r.rlim_cur == RLIM_INFINITY ? "'unlimited'" :
rlim_to_string( r.rlim_cur, cur, sizeof(cur)));
} else {
verbose("Can't propagate %s of %s from submit host: %m",
rlimit_name,
r.rlim_cur == RLIM_INFINITY ? "'unlimited'" :
rlim_to_string( r.rlim_cur, cur, sizeof(cur)));
}
return SLURM_ERROR;
}
debug2( "_set_limit: %s setrlimit %s succeeded",
u_req_propagate?"user":"conf", rlimit_name );
return SLURM_SUCCESS;
}
开发者ID:A1ve5,项目名称:slurm,代码行数:89,代码来源:ulimits.c
示例16: DB_Search
/* Search the DB for any entry related to the file being received */
static int DB_Search(const char *f_name, char *c_sum, Eventinfo *lf)
{
int p = 0;
size_t sn_size;
int agent_id;
char *saved_sum;
char *saved_name;
FILE *fp;
SyscheckSum oldsum;
SyscheckSum newsum;
/* Get db pointer */
fp = DB_File(lf->location, &agent_id);
if (!fp) {
merror("%s: Error handling integrity database.", ARGV0);
sdb.db_err++;
lf->data = NULL;
return (0);
}
/* Read the integrity file and search for a possible entry */
if (fgetpos(fp, &sdb.init_pos) == -1) {
merror("%s: Error handling integrity database (fgetpos).", ARGV0);
return (0);
}
/* Loop over the file */
while (fgets(sdb.buf, OS_MAXSTR, fp) != NULL) {
/* Ignore blank lines and lines with a comment */
if (sdb.buf[0] == '\n' || sdb.buf[0] == '#') {
fgetpos(fp, &sdb.init_pos); /* Get next location */
continue;
}
/* Get name */
saved_name = strchr(sdb.buf, ' ');
if (saved_name == NULL) {
merror("%s: Invalid integrity message in the database.", ARGV0);
fgetpos(fp, &sdb.init_pos); /* Get next location */
continue;
}
*saved_name = '\0';
saved_name++;
/* New format - with a timestamp */
if (*saved_name == '!') {
saved_name = strchr(saved_name, ' ');
if (saved_name == NULL) {
merror("%s: Invalid integrity message in the database", ARGV0);
fgetpos(fp, &sdb.init_pos); /* Get next location */
continue;
}
saved_name++;
}
/* Remove newline from saved_name */
sn_size = strlen(saved_name);
sn_size -= 1;
if (saved_name[sn_size] == '\n') {
saved_name[sn_size] = '\0';
}
/* If name is different, go to next one */
if (strcmp(f_name, saved_name) != 0) {
/* Save current location */
fgetpos(fp, &sdb.init_pos);
continue;
}
saved_sum = sdb.buf;
/* First three bytes are for frequency check */
saved_sum += 3;
/* Checksum match, we can just return and keep going */
if (strcmp(saved_sum, c_sum) == 0) {
lf->data = NULL;
return (0);
}
debug2("Agent: %d, location: <%s>, file: <%s>, sum: <%s>, saved: <%s>", agent_id, lf->location, f_name, c_sum, saved_sum);
/* If we reached here, the checksum of the file has changed */
if (saved_sum[-3] == '!') {
p++;
if (saved_sum[-2] == '!') {
p++;
if (saved_sum[-1] == '!') {
p++;
} else if (saved_sum[-1] == '?') {
p += 2;
}
}
}
/* Check the number of changes */
//.........这里部分代码省略.........
开发者ID:Cryptophobia,项目名称:ossec-wazuh,代码行数:101,代码来源:syscheck.c
示例17: set_user_limits
int set_user_limits(stepd_step_rec_t *job)
{
#ifdef RLIMIT_AS
#define SLURM_RLIMIT_VSIZE RLIMIT_AS
#define SLURM_RLIMIT_VNAME "RLIMIT_AS"
#elif defined(RLIMIT_DATA)
/* RLIMIT_DATA is useless on many systems which provide anonymous
* mmap()'s in addition to brk(), use it here only as a fallback for
* oddball systems lacking RLIMIT_AS. */
#define SLURM_RLIMIT_VSIZE RLIMIT_DATA
#define SLURM_RLIMIT_VNAME "RLIMIT_DATA"
#endif
slurm_rlimits_info_t *rli;
struct rlimit r;
rlim_t task_mem_bytes;
#ifdef SLURM_RLIMIT_VSIZE
uint16_t vsize_factor;
#endif
if (getrlimit(RLIMIT_CPU, &r) == 0) {
if (r.rlim_max != RLIM_INFINITY) {
error("SLURM process CPU time limit is %d seconds",
(int) r.rlim_max);
}
}
for (rli = get_slurm_rlimits_info(); rli->name; rli++)
_set_limit( job->env, rli );
/* Set soft and hard rss and vsize limit for this process,
* handle job limit (for all spawned proc
|
请发表评论