diff --git a/honoka/plugins/primeprediction.cpp b/honoka/plugins/primeprediction.cpp index 6fcdc42..8d19659 100644 --- a/honoka/plugins/primeprediction.cpp +++ b/honoka/plugins/primeprediction.cpp @@ -39,6 +39,7 @@ #include #include +#include // �ץ饤�����󲽤Τ��ޤ��ʤ��Ǥ��� @@ -48,7 +49,13 @@ PrimePrediction::PrimePrediction(ConfigPointer cfg) : Predictor(cfg) { m_iconv.set_encoding ("EUC-JP"); - con = false; + mid = shmget(IPC_PRIVATE,sizeof(bool),IPC_CREAT | 0666); + if (mid != -1) { + con = (bool *)shmat(mid,0,0); + con[0] = false; + // shmat���Ի��Υ��顼�����ϡ��� + // Ʊ��ץ����dzμ¤�Ʊ��ID�ʤ鼺�Ԥ��褦���ʤ����⤹�뤬�� + } lookup_method = cfg->read(HONOKA_CONFIG_PRIME_PREDICTION_LM,String(HONOKA_DEFAULT_PRIME_PREDICTION_LM)); if ((lookup_method != "lookup") && (lookup_method != "lookup_all") && @@ -67,6 +74,7 @@ PrimePrediction::~PrimePrediction() { disconnect(); + if (mid != -1) shmctl(mid,IPC_RMID,0); } @@ -105,7 +113,8 @@ ResultList PrimePrediction::getPredictionList(const WideString &str) { ResultList l; - if (!con) return l; + if (mid == -1) return l; + if (!con[0]) return l; String s = lookup_method + "\t"; String t; m_iconv.convert(t,str); @@ -142,12 +151,13 @@ */ void PrimePrediction::disconnect() { - if (!con) return; + if (mid == -1) return; + if (con[0]) return; String s = "close\n"; write(ifd,s.c_str(),s.length()); close(ifd); close(ofd); - con = false; + con[0] = false; } @@ -156,17 +166,18 @@ */ bool PrimePrediction::connect() { + if (mid == -1) return false; int in_fd[2],out_fd[2],i; - if (con) return true; + if (con[0]) return true; if (pipe(in_fd) == -1) return false; if (pipe(out_fd) == -1) return false; - switch(vfork()) { + switch(fork()) { case -1: { close(in_fd[0]); close(in_fd[1]); close(out_fd[0]); close(out_fd[1]); - con = false; + con[0] = false; return false; } case 0: { @@ -176,9 +187,9 @@ dup2(out_fd[1],1); close(in_fd[0]); close(out_fd[1]); - con = true; + con[0] = true; execlp("prime",NULL); - con = false; + con[0] = false; _exit(0); } } @@ -195,7 +206,8 @@ */ bool PrimePrediction::isConnected() { - return con; + if (mid == -1) return false; + return con[0]; } diff --git a/honoka/plugins/primeprediction.h b/honoka/plugins/primeprediction.h index a5ce978..a8e1a4f 100644 --- a/honoka/plugins/primeprediction.h +++ b/honoka/plugins/primeprediction.h @@ -36,6 +36,8 @@ #include #include #include +#include +#include /** @author TAM (Teppei Tamra) @@ -59,8 +61,9 @@ String lookup_method; int ifd; int ofd; - bool con; + bool *con; IConvert m_iconv; + int mid; protected: ResultEntry parser(const String &str); };