Change pid to tid only

This commit is contained in:
jun7 2018-06-08 22:37:36 +09:00
parent 393be6fc71
commit a0fc970dbc
3 changed files with 13 additions and 13 deletions

2
ab.c
View File

@ -206,7 +206,7 @@ int main(int argc, char **argv)
{
wyebclient(argv[0]);
}
else if (g_str_has_prefix(argv[1], WYEBPREFIX))
else if (!strcmp(argv[1], WYEBPREFIX))
{
init();
wyebsvr(argc, argv, datafunc);

View File

@ -18,9 +18,8 @@ along with wyebrun. If not, see <http://www.gnu.org/licenses/>.
*/
//getpid
#include <sys/types.h>
#include <unistd.h>
//gettid
#include <sys/syscall.h>
//flock
#include <sys/file.h>
@ -213,12 +212,12 @@ static gboolean svrinit(char *caller)
bool wyebsvr(int argc, char **argv, wyebdataf func)
{
if (argc < 2 || !g_str_has_prefix(argv[1], PREFIX)) return false;
if (argc < 3 || strcmp(argv[1], PREFIX)) return false;
svrexe = argv[0];
dataf = func;
sloop = g_main_loop_new(NULL, false);
g_idle_add((GSourceFunc)svrinit, argv[1]);
g_idle_add((GSourceFunc)svrinit, argv[2]);
g_main_loop_run(sloop);
return true;
@ -276,8 +275,7 @@ static Client *makecli()
{
Client *cli = g_new0(Client, 1);
g_mutex_init(&cli->retm);
cli->pid = g_strdup_printf(PREFIX"%d-%d",
getpid(), GPOINTER_TO_INT(g_thread_self()));
cli->pid = g_strdup_printf("%d", (pid_t)syscall(SYS_gettid));
cli->wctx = g_main_context_new();
cli->loop = g_main_loop_new(cli->wctx, true);
@ -387,9 +385,10 @@ static char *request(char *exe, Com type, bool caller, char *data)
g_source_attach(tout, cli->wctx);
char **argv = g_new0(char*, 3);
char **argv = g_new0(char*, 4);
argv[0] = exe;
argv[1] = cli->pid;
argv[1] = PREFIX;
argv[2] = cli->pid;
GError *err = NULL;
if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, &err))
@ -494,7 +493,7 @@ static gboolean tcinputcb(GIOChannel *ch, GIOCondition c, char *exe)
GThreadPool *pool = g_thread_pool_new(testget, exe, 44, false, NULL);
start = g_get_monotonic_time();
for (int i = 0; i < 10000; i++)
for (int i = 0; i < 100; i++)
{
char *is = g_strdup_printf("l%d", i);
//g_print("loop %d ret %s\n", i, wyebget(exe, is));

View File

@ -23,7 +23,7 @@ along with wyebrun. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#include <glib/gstdio.h>
#define WYEBPREFIX "-wyeb"
#define WYEBPREFIX "--wyebrun"
#define WYEBKEEPSEC 3
//client
@ -43,7 +43,8 @@ typedef char *(*wyebdataf)(char *data);
bool wyebsvr(int argc, char **argv, wyebdataf func);
//or if there is own GMainLoop
void wyebwatch(char *exe, char *caller, wyebdataf func);
//the caller is used to send the res meaning we are ready.
//the caller is sent as 'exe --wyebrun 9999' and
//used to send the res meaning we are ready.
//3 sec left or client will die