/* * 宏的数字变成字符串 * 1. 宏中的#的功能是将其后面的宏参数进行字符串化操作(Stringizing operator) * 简单说就是在它引用的宏变量的左右各加上一个双引号 * 2. #@是加单引号(Charizing Operator)gcc/clang并不支持它 * 3. 宏中遇到#或##时就不会再展开宏中嵌套的宏了, 需要使用一个中间转换宏达到展开宏的目的 * 4. ##的功能,它可以拼接符号(Token-pasting operator) */ static void macro_as_part_of_string(void) { #define CONFIG_BAUDRATE 2000000 #define __STRING(x) #x /* (#x) is invalid */ #define STRING(x) __STRING(x) #define BOOTARGS_CONSOLE "console=ttyS3,"STRING(CONFIG_BAUDRATE)"n8 " printf("%s\n", BOOTARGS_CONSOLE); char *pChar = "hello"; char *pChar2 = __STRING(hello); /* hello -> "hello" */ if(!strcmp(pChar, pChar2)) { printf("pChar:%s is equal to pChar2:%s\n", pChar, pChar2); } /* gcc/clang not support #@ #define TOCHAR(x) #@x char c = TOCHAR(A); printf("c is %c\n", c); */ printf("%s\n", __STRING(__FILE__)); printf("%s\n", STRING(__FILE__)); #define paster(n) printf("token"#n" = %d\n", token##n) int token9 = 100; paster(9); #define WIDEN2(x) L##x #define WIDEN(x) WIDEN2(x) #define __WFILE__ WIDEN(__FILE__) printf("%s\n", /*L*/"hello"); }
void agentx_config_init (void) { int agent_role = netsnmp_ds_get_boolean (NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE); /* * Common tokens for master/subagent */ netsnmp_register_default_domain ("agentx", "unix tcp"); netsnmp_register_default_target ("agentx", "unix", NETSNMP_AGENTX_SOCKET); netsnmp_register_default_target ("agentx", "tcp", "localhost:" __STRING (AGENTX_PORT)); agentx_register_config_handler ("agentxsocket", agentx_parse_agentx_socket, NULL, "AgentX bind address"); #ifdef USING_AGENTX_MASTER_MODULE /* * tokens for master agent */ if (MASTER_AGENT == agent_role) { snmpd_register_config_handler ("master", agentx_parse_master, NULL, "specify 'agentx' for AgentX support"); agentx_register_config_handler ("agentxperms", agentx_parse_agentx_perms, NULL, "AgentX socket permissions: socket_perms [directory_perms [username|userid [groupname|groupid]]]"); agentx_register_config_handler ("agentxRetries", agentx_parse_agentx_retries, NULL, "AgentX Retries"); agentx_register_config_handler ("agentxTimeout", agentx_parse_agentx_timeout, NULL, "AgentX Timeout (seconds)"); } #endif /* USING_AGENTX_MASTER_MODULE */ #ifdef USING_AGENTX_SUBAGENT_MODULE /* * tokens for master agent */ if (SUB_AGENT == agent_role) { /* * set up callbacks to initiate master agent pings for this session */ netsnmp_ds_register_config (ASN_INTEGER, netsnmp_ds_get_string (NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE), "agentxPingInterval", NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL); /* ping and/or reconnect by default every 15 seconds */ netsnmp_ds_set_int (NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL, 15); } #endif /* USING_AGENTX_SUBAGENT_MODULE */ }
" mov r3, r0 /* ps_strings */ \n" " /* Get argc, argv, and envp from stack */ \n" " ldr r0, [sp, #0x0000] \n" " add r1, sp, #0x0004 \n" " add r2, r1, r0, lsl #2 \n" " add r2, r2, #0x0004 \n" "\n" " /* Ensure the stack is properly aligned before calling C code. */\n" #if 1 " bic sp, sp, #7" /*__STRING(STACKALIGNBYTES)*/ " \n" #endif " sub sp, sp, #8 \n" " str r5, [sp, #4] \n" " str r4, [sp, #0] \n" "\n" " b " __STRING(___start) " "); /* " b " __STRING(_C_LABEL(___start)) " "); */ void ___start(int argc, char **argv, char **envp, void *ps_strings, const void *obj, void (*cleanup)(void)) { char *s; environ = envp; if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(__progname, '/')) == NULL) __progname = argv[0];
static int bl_init(bl_t b, bool srv) { static int one = 1; /* AF_UNIX address of local logger */ mode_t om; int rv, serrno; struct sockaddr_un *sun = &b->b_sun; #ifndef SOCK_NONBLOCK #define SOCK_NONBLOCK 0 #endif #ifndef SOCK_CLOEXEC #define SOCK_CLOEXEC 0 #endif #ifndef SOCK_NOSIGPIPE #define SOCK_NOSIGPIPE 0 #endif BL_LOCK(b); if (b->b_fd == -1) { b->b_fd = socket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK|SOCK_NOSIGPIPE, 0); if (b->b_fd == -1) { bl_log(b->b_fun, LOG_ERR, "%s: socket failed (%m)", __func__); BL_UNLOCK(b); return -1; } #if SOCK_CLOEXEC == 0 fcntl(b->b_fd, F_SETFD, FD_CLOEXEC); #endif #if SOCK_NONBLOCK == 0 fcntl(b->b_fd, F_SETFL, fcntl(b->b_fd, F_GETFL) | O_NONBLOCK); #endif #if SOCK_NOSIGPIPE == 0 #ifdef SO_NOSIGPIPE int o = 1; setsockopt(b->b_fd, SOL_SOCKET, SO_NOSIGPIPE, &o, sizeof(o)); #else signal(SIGPIPE, SIG_IGN); #endif #endif } if (bl_isconnected(b)) { BL_UNLOCK(b); return 0; } /* * We try to connect anyway even when we are a server to verify * that no other server is listening to the socket. If we succeed * to connect and we are a server, someone else owns it. */ rv = connect(b->b_fd, (const void *)sun, (socklen_t)sizeof(*sun)); if (rv == 0) { if (srv) { bl_log(b->b_fun, LOG_ERR, "%s: another daemon is handling `%s'", __func__, sun->sun_path); goto out; } } else { if (!srv) { /* * If the daemon is not running, we just try a * connect, so leave the socket alone until it does * and only log once. */ if (b->b_connected != 1) { bl_log(b->b_fun, LOG_DEBUG, "%s: connect failed for `%s' (%m)", __func__, sun->sun_path); b->b_connected = 1; } BL_UNLOCK(b); return -1; } bl_log(b->b_fun, LOG_DEBUG, "Connected to blacklist server", __func__); } if (srv) { (void)unlink(sun->sun_path); om = umask(0); rv = bind(b->b_fd, (const void *)sun, (socklen_t)sizeof(*sun)); serrno = errno; (void)umask(om); errno = serrno; if (rv == -1) { bl_log(b->b_fun, LOG_ERR, "%s: bind failed for `%s' (%m)", __func__, sun->sun_path); goto out; } } b->b_connected = 0; #define GOT_FD 1 #if defined(LOCAL_CREDS) #define CRED_LEVEL 0 #define CRED_NAME LOCAL_CREDS #define CRED_SC_UID sc_euid #define CRED_SC_GID sc_egid #define CRED_MESSAGE SCM_CREDS #define CRED_SIZE SOCKCREDSIZE(NGROUPS_MAX) #define CRED_TYPE struct sockcred #define GOT_CRED 2 #elif defined(SO_PASSCRED) #define CRED_LEVEL SOL_SOCKET #define CRED_NAME SO_PASSCRED #define CRED_SC_UID uid #define CRED_SC_GID gid #define CRED_MESSAGE SCM_CREDENTIALS #define CRED_SIZE sizeof(struct ucred) #define CRED_TYPE struct ucred #define GOT_CRED 2 #else #define GOT_CRED 0 /* * getpeereid() and LOCAL_PEERCRED don't help here * because we are not a stream socket! */ #define CRED_SIZE 0 #define CRED_TYPE void * __unused #endif #ifdef CRED_LEVEL if (setsockopt(b->b_fd, CRED_LEVEL, CRED_NAME, &one, (socklen_t)sizeof(one)) == -1) { bl_log(b->b_fun, LOG_ERR, "%s: setsockopt %s " "failed (%m)", __func__, __STRING(CRED_NAME)); goto out; } #endif BL_UNLOCK(b); return 0; out: bl_reset(b, true); BL_UNLOCK(b); return -1; }
libzfs_handle_t * libzfs_init(void) { libzfs_handle_t *hdl; #ifdef __APPLE__ struct vfsconf vfc; struct stat sb; int loaded; /* Attempt to load zfs kext if its not already loaded. */ if (getvfsbyname("zfs", &vfc) != 0) { int pick = 0; int i; /* Find all possible zfs kext versions. */ getkextvers(kextpaths[0], &kextvers[0]); getkextvers(kextpaths[1], &kextvers[1]); /* Pick the newest one. */ for (i = 0; i < 2; ++i) { if (kextvers[i] > kextvers[pick]) pick = i; } loaded = load_zfs_kext(kextpaths[pick]); ASSERT(loaded == 0); } /* Attempt to create "/etc/zfs" its not already there. */ if (getuid() == 0 && stat("/etc/zfs", &sb)!= 0 && errno == ENOENT) { (void) mkdir("/etc/zfs", 0755); } #endif if ((hdl = calloc(sizeof (libzfs_handle_t), 1)) == NULL) { return (NULL); } if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { free(hdl); return (NULL); } else { /* Perform special version ceck ioctl() to unlock user-kernel * interface. This serves as protection against using userland * tools of one implementation against kernel land of another * implementation. */ zfs_cmd_t vers_zc = {0}; strncpy(vers_zc.zc_name, __STRING(MACZFS_ID), sizeof(vers_zc.zc_name)-1); vers_zc.zc_value[0] = ZFS_IOC_NUM(ZFS_IOC__LAST_USED); vers_zc.zc_value[1] = MACZFS_VERS_MAJOR; vers_zc.zc_value[2] = MACZFS_VERS_MINOR; vers_zc.zc_value[3] = MACZFS_VERS_PATCH; hdl->libzfs_log_str = NULL; if (zfs_ioctl(hdl, ZFS_IOC__VERSION_CHECK, &vers_zc) != 0) { /* kernel - user version mismatch or kernel side not ready. */ free(hdl); return (NULL); } } #ifndef __APPLE__ if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) { (void) close(hdl->libzfs_fd); free(hdl); return (NULL); } #endif /*!__APPLE__*/ hdl->libzfs_sharetab = fopen("/etc/dfs/sharetab", "r"); zfs_prop_init(); return (hdl); }