2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
13 Startup, and shutdown the memcached servers.
16 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
26 #include <libmemcached/memcached.h>
30 void server_startup(server_startup_st
*construct
)
34 if ((construct
->server_list
= getenv("MEMCACHED_SERVERS")))
36 printf("servers %s\n", construct
->server_list
);
37 construct
->servers
= memcached_servers_parse(construct
->server_list
);
38 construct
->server_list
= NULL
;
44 char server_string_buffer
[8096];
46 end_ptr
= server_string_buffer
;
48 for (x
= 0; x
< construct
->count
; x
++)
50 char buffer
[1024]; /* Nothing special for number */
54 sprintf(buffer
, "/tmp/%umemc.pid", x
);
55 if (access(buffer
, F_OK
) == 0)
57 FILE *fp
= fopen(buffer
, "r");
62 if (fgets(buffer
, sizeof(buffer
), fp
) != NULL
)
64 pid_t pid
= (pid_t
)atol(buffer
);
75 sprintf(buffer
, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128",
76 MEMCACHED_BINARY
, x
, x
+ TEST_PORT_BASE
, x
+ TEST_PORT_BASE
);
80 sprintf(buffer
, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u",
81 MEMCACHED_BINARY
, x
, x
+ TEST_PORT_BASE
, x
+ TEST_PORT_BASE
);
83 fprintf(stderr
, "STARTING SERVER: %s\n", buffer
);
84 status
= system(buffer
);
85 count
= sprintf(end_ptr
, "localhost:%u,", x
+ TEST_PORT_BASE
);
90 construct
->server_list
= strdup(server_string_buffer
);
92 printf("servers %s\n", construct
->server_list
);
93 construct
->servers
= memcached_servers_parse(construct
->server_list
);
96 assert(construct
->servers
);
98 srandom((unsigned int)time(NULL
));
100 for (x
= 0; x
< memcached_server_list_count(construct
->servers
); x
++)
102 printf("\t%s : %u\n", construct
->servers
[x
].hostname
, construct
->servers
[x
].port
);
103 assert(construct
->servers
[x
].fd
== -1);
104 assert(construct
->servers
[x
].cursor_active
== 0);
110 void server_shutdown(server_startup_st
*construct
)
114 if (construct
->server_list
)
116 for (x
= 0; x
< construct
->count
; x
++)
118 char buffer
[1024]; /* Nothing special for number */
119 sprintf(buffer
, "cat /tmp/%umemc.pid | xargs kill", x
);
120 /* We have to check the return value of this or the compiler will yell */
121 int sys_ret
= system(buffer
);
122 assert(sys_ret
!= -1);
123 sprintf(buffer
, "/tmp/%umemc.pid", x
);
127 free(construct
->server_list
);