在cgi-bin下运行c程序时无法存储密钥:SYSTEM ERROR

时间:2013-04-12 08:17:06

标签: c apache memcached libmemcached

当我从CentOS 6.4上的命令行运行以下程序时,我得到了预期的结果,但是当我将它作为Apache cgi运行时,我错误Couldn't store key: SYSTEM ERROR错误。我正在通过同一个用户运行Memcached,Apache和程序。

我可能做错了什么?

    #include<stdio.h>
    #include<string.h>
    #include <libmemcached/memcached.h>

    int main(int argc, char **argv) {
        memcached_server_st *servers = NULL;
        memcached_st *memc;
        memcached_return rc;
        char *key= "keystring";
        char *value= "keyvalue";
        char *key1= "keystring1";
        char *value1= "keyvalue1    ";

        memc= memcached_create(NULL);
        servers= memcached_server_list_append(servers, "localhost", 11211, &rc);
        rc= memcached_server_push(memc, servers);

        printf("Content-Type: text/plain;charset=us-ascii\n\n");

        if (rc == MEMCACHED_SUCCESS)
            printf("Added server successfully\n");
        else
            printf("Couldn't add server: %s\n",memcached_strerror(memc, rc));

        rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);

        if (rc == MEMCACHED_SUCCESS)
            printf("Key stored successfully\n");
        else
        printf("Couldn't store key: %s\n",memcached_strerror(memc, rc));

        char *keys[]= {"keystring", "keystring1"};
        size_t key_length[]= {9, 10};
        unsigned int x;
        uint32_t flags;

        char return_key[MEMCACHED_MAX_KEY];
        size_t return_key_length;
        char *return_value;
        size_t return_value_length;

        rc= memcached_mget(memc, keys, key_length, 2);

        x= 0;

     if (rc == MEMCACHED_SUCCESS)
      {
            while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
                                              &return_value_length, &flags, &rc)))
            {
                if (rc == MEMCACHED_SUCCESS)
                {
                  printf("Key %s returned %s\n",return_key, return_value);
                }
            }
        }

        return 0;
    }

1 个答案:

答案 0 :(得分:0)

最后通过禁用SELINUX摆脱了错误。