summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-01-13 19:20:49 (UTC)
committer mickeyl <mickeyl>2004-01-13 19:20:49 (UTC)
commit81b48fa5be4806e3afa64a0d1fa254fbdf9b7315 (patch) (unidiff)
treea28289a6d048ec80e359233a6b72bd946a9b8eb8
parent399cf645e63e53043975fa2b26768d8db6d83ee4 (diff)
downloadopie-81b48fa5be4806e3afa64a0d1fa254fbdf9b7315.zip
opie-81b48fa5be4806e3afa64a0d1fa254fbdf9b7315.tar.gz
opie-81b48fa5be4806e3afa64a0d1fa254fbdf9b7315.tar.bz2
cleanup and unify source layout
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/oprocess.cpp193
-rw-r--r--libopie2/opiecore/oprocess.h80
2 files changed, 109 insertions, 164 deletions
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp
index fb51bf9..f1a5f3b 100644
--- a/libopie2/opiecore/oprocess.cpp
+++ b/libopie2/opiecore/oprocess.cpp
@@ -1,95 +1,74 @@
1/* 1/*
2 2                This file is part of the Opie Project
3 $Id$ 3             Copyright (C) 2002-2004 Holger Freyther <zecke@handhelds.org>
4 4 and The Opie Team <opie-devel@handhelds.org>
5 This file is part of the KDE libraries 5 =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at)
6 Copyright (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) 6 .=l.
7 7          .>+-=
8 This library is free software; you can redistribute it and/or 8_;:,     .>    :=|. This program is free software; you can
9 modify it under the terms of the GNU Library General Public 9.> <`_,   >  .   <= redistribute it and/or modify it under
10 License as published by the Free Software Foundation; either 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11 version 2 of the License, or (at your option) any later version. 11.="- .-=="i,     .._ License as published by the Free Software
12 12- .   .-<_>     .<> Foundation; either version 2 of the License,
13 This library is distributed in the hope that it will be useful, 13    ._= =}       : or (at your option) any later version.
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14   .%`+i>       _;_.
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15   .i_,=:_.      -<s. This program is distributed in the hope that
16 Library General Public License for more details. 16    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17 17   : ..    .:,     . . . without even the implied warranty of
18 You should have received a copy of the GNU Library General Public License 18   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19 along with this library; see the file COPYING.LIB. If not, write to 19 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22:     =  ...= . :.=-
23-.   .:....=;==+<; You should have received a copy of the GNU
24 -_. . .   )=.  = Library General Public License along with
25   --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
22
23*/ 29*/
24 30
25
26//
27// KPROCESS -- A class for handling child processes in KDE without
28// having to take care of Un*x specific implementation details
29//
30// version 0.3.1, Jan 8th 1998
31//
32// (C) Christian Czezatke
33// e9025461@student.tuwien.ac.at
34//
35// Changes:
36//
37// March 2nd, 1998: Changed parameter list for KShellProcess:
38// Arguments are now placed in a single string so that
39// <shell> -c <commandstring> is passed to the shell
40// to make the use of "operator<<" consistent with KProcess
41//
42//
43// Ported by Holger Freyther
44// <zekce> Harlekin: oprocess and say it was ported to Qt by the Opie developers an Qt 2
45
46
47
48#include "oprocess.h"
49#define _MAY_INCLUDE_KPROCESSCONTROLLER_
50#include "oprocctrl.h" 31#include "oprocctrl.h"
51 32
52//#include <config.h> 33/* OPIE */
34#include <opie2/oprocess.h>
35
36/* QT */
53 37
38#include <qapplication.h>
54#include <qfile.h> 39#include <qfile.h>
55#include <qsocketnotifier.h> 40#include <qmap.h>
56#include <qregexp.h> 41#include <qregexp.h>
42#include <qsocketnotifier.h>
57 43
58#include <sys/time.h> 44/* STD */
59#include <sys/types.h>
60#include <sys/stat.h>
61#include <sys/socket.h>
62
63#include <errno.h> 45#include <errno.h>
64#include <fcntl.h> 46#include <fcntl.h>
47#include <pwd.h>
65#include <stdlib.h> 48#include <stdlib.h>
66#include <signal.h> 49#include <signal.h>
67#include <stdio.h> 50#include <stdio.h>
68#include <string.h> 51#include <string.h>
52#include <sys/time.h>
53#include <sys/types.h>
54#include <sys/stat.h>
55#include <sys/socket.h>
69#include <unistd.h> 56#include <unistd.h>
70#ifdef HAVE_SYS_SELECT_H 57#ifdef HAVE_SYS_SELECT_H
71#include <sys/select.h> 58#include <sys/select.h>
72#endif 59#endif
73#ifdef HAVE_INITGROUPS 60#ifdef HAVE_INITGROUPS
74#include <grp.h> 61#include <grp.h>
75#endif 62#endif
76#include <pwd.h>
77
78#include <qapplication.h>
79#include <qmap.h>
80//#include <kdebug.h>
81
82/////////////////////////////
83// public member functions //
84/////////////////////////////
85 63
86class OProcessPrivate 64class OProcessPrivate
87{ 65{
88public: 66public:
89 OProcessPrivate() : useShell(false) { } 67 OProcessPrivate() : useShell( false )
68 { }
90 69
91 bool useShell; 70 bool useShell;
92 QMap<QString,QString> env; 71 QMap<QString,QString> env;
93 QString wd; 72 QString wd;
94 QCString shell; 73 QCString shell;
95}; 74};
@@ -140,55 +119,49 @@ void OProcess::init ( )
140 OProcessController::theOProcessController->addOProcess(this); 119 OProcessController::theOProcessController->addOProcess(this);
141 out[0] = out[1] = -1; 120 out[0] = out[1] = -1;
142 in[0] = in[1] = -1; 121 in[0] = in[1] = -1;
143 err[0] = err[1] = -1; 122 err[0] = err[1] = -1;
144} 123}
145 124
146void 125void OProcess::setEnvironment( const QString &name, const QString &value )
147OProcess::setEnvironment(const QString &name, const QString &value)
148{ 126{
149 if (!d) 127 if (!d)
150 d = new OProcessPrivate; 128 d = new OProcessPrivate;
151 d->env.insert(name, value); 129 d->env.insert(name, value);
152} 130}
153 131
154void 132void OProcess::setWorkingDirectory( const QString &dir )
155OProcess::setWorkingDirectory(const QString &dir)
156{ 133{
157 if (!d) 134 if (!d)
158 d = new OProcessPrivate; 135 d = new OProcessPrivate;
159 d->wd = dir; 136 d->wd = dir;
160} 137}
161 138
162void 139void OProcess::setupEnvironment()
163OProcess::setupEnvironment()
164{ 140{
165 if (d) 141 if (d)
166 { 142 {
167 QMap<QString,QString>::Iterator it; 143 QMap<QString,QString>::Iterator it;
168 for(it = d->env.begin(); it != d->env.end(); ++it) 144 for(it = d->env.begin(); it != d->env.end(); ++it)
169 setenv(QFile::encodeName(it.key()).data(), 145 setenv(QFile::encodeName(it.key()).data(),
170 QFile::encodeName(it.data()).data(), 1); 146 QFile::encodeName(it.data()).data(), 1);
171 if (!d->wd.isEmpty()) 147 if (!d->wd.isEmpty())
172 chdir(QFile::encodeName(d->wd).data()); 148 chdir(QFile::encodeName(d->wd).data());
173 } 149 }
174} 150}
175 151
176void 152void OProcess::setRunPrivileged( bool keepPrivileges )
177OProcess::setRunPrivileged(bool keepPrivileges)
178{ 153{
179 keepPrivs = keepPrivileges; 154 keepPrivs = keepPrivileges;
180} 155}
181 156
182bool 157bool OProcess::runPrivileged() const
183OProcess::runPrivileged() const
184{ 158{
185 return keepPrivs; 159 return keepPrivs;
186} 160}
187 161
188
189OProcess::~OProcess() 162OProcess::~OProcess()
190{ 163{
191 // destroying the OProcess instance sends a SIGKILL to the 164 // destroying the OProcess instance sends a SIGKILL to the
192 // child process (if it is running) after removing it from the 165 // child process (if it is running) after removing it from the
193 // list of valid processes (if the process is not started as 166 // list of valid processes (if the process is not started as
194 // "DontCare") 167 // "DontCare")
@@ -221,15 +194,17 @@ void OProcess::detach()
221 closeStdout(); 194 closeStdout();
222 closeStderr(); 195 closeStderr();
223} 196}
224 197
225bool OProcess::setExecutable(const QString& proc) 198bool OProcess::setExecutable(const QString& proc)
226{ 199{
227 if (runs) return false; 200 if ( runs )
201 return false;
228 202
229 if (proc.isEmpty()) return false; 203 if ( proc.isEmpty() )
204 return false;
230 205
231 if (!arguments.isEmpty()) 206 if (!arguments.isEmpty())
232 arguments.remove(arguments.begin()); 207 arguments.remove(arguments.begin());
233 arguments.prepend(QFile::encodeName(proc)); 208 arguments.prepend(QFile::encodeName(proc));
234 209
235 return true; 210 return true;
@@ -313,12 +288,13 @@ bool OProcess::start(RunMode runmode, Communication comm)
313 288
314 // We do this in the parent because if we do it in the child process 289 // We do this in the parent because if we do it in the child process
315 // gdb gets confused when the application runs from gdb. 290 // gdb gets confused when the application runs from gdb.
316 uid_t uid = getuid(); 291 uid_t uid = getuid();
317 gid_t gid = getgid(); 292 gid_t gid = getgid();
318#ifdef HAVE_INITGROUPS 293#ifdef HAVE_INITGROUPS
294
319 struct passwd *pw = getpwuid(uid); 295 struct passwd *pw = getpwuid(uid);
320#endif 296#endif
321 297
322 int fd[2]; 298 int fd[2];
323 if (0 > pipe(fd)) 299 if (0 > pipe(fd))
324 { 300 {
@@ -338,15 +314,17 @@ bool OProcess::start(RunMode runmode, Communication comm)
338 if (fd[0]) 314 if (fd[0])
339 close(fd[0]); 315 close(fd[0]);
340 if (!runPrivileged()) 316 if (!runPrivileged())
341 { 317 {
342 setgid(gid); 318 setgid(gid);
343#if defined( HAVE_INITGROUPS) 319#if defined( HAVE_INITGROUPS)
320
344 if(pw) 321 if(pw)
345 initgroups(pw->pw_name, pw->pw_gid); 322 initgroups(pw->pw_name, pw->pw_gid);
346#endif 323#endif
324
347 setuid(uid); 325 setuid(uid);
348 } 326 }
349 // The child process 327 // The child process
350 if(!commSetupDoneC()) 328 if(!commSetupDoneC())
351 qWarning( "Could not finish comm setup in child!" ); 329 qWarning( "Could not finish comm setup in child!" );
352 330
@@ -388,13 +366,14 @@ bool OProcess::start(RunMode runmode, Communication comm)
388 // the parent continues here 366 // the parent continues here
389 367
390 // Discard any data for stdin that might still be there 368 // Discard any data for stdin that might still be there
391 input_data = 0; 369 input_data = 0;
392 370
393 // Check whether client could be started. 371 // Check whether client could be started.
394 if (fd[0]) for(;;) 372 if ( fd[ 0 ] )
373 for ( ;; )
395 { 374 {
396 char resultByte; 375 char resultByte;
397 int n = ::read(fd[0], &resultByte, 1); 376 int n = ::read(fd[0], &resultByte, 1);
398 if (n == 1) 377 if (n == 1)
399 { 378 {
400 // Error 379 // Error
@@ -445,44 +424,34 @@ bool OProcess::kill(int signo)
445 if (0 != pid_) 424 if (0 != pid_)
446 rv= (-1 != ::kill(pid_, signo)); 425 rv= (-1 != ::kill(pid_, signo));
447 // probably store errno somewhere... 426 // probably store errno somewhere...
448 return rv; 427 return rv;
449} 428}
450 429
451
452
453bool OProcess::isRunning() const 430bool OProcess::isRunning() const
454{ 431{
455 return runs; 432 return runs;
456} 433}
457 434
458
459
460pid_t OProcess::pid() const 435pid_t OProcess::pid() const
461{ 436{
462 return pid_; 437 return pid_;
463} 438}
464 439
465
466
467bool OProcess::normalExit() const 440bool OProcess::normalExit() const
468{ 441{
469 int _status = status; 442 int _status = status;
470 return (pid_ != 0) && (!runs) && (WIFEXITED((_status))); 443 return (pid_ != 0) && (!runs) && (WIFEXITED((_status)));
471} 444}
472 445
473
474
475int OProcess::exitStatus() const 446int OProcess::exitStatus() const
476{ 447{
477 int _status = status; 448 int _status = status;
478 return WEXITSTATUS((_status)); 449 return WEXITSTATUS((_status));
479} 450}
480 451
481
482
483bool OProcess::writeStdin(const char *buffer, int buflen) 452bool OProcess::writeStdin(const char *buffer, int buflen)
484{ 453{
485 bool rv; 454 bool rv;
486 455
487 // if there is still data pending, writing new data 456 // if there is still data pending, writing new data
488 // to stdout is not allowed (since it could also confuse 457 // to stdout is not allowed (since it could also confuse
@@ -580,53 +549,36 @@ bool OProcess::closeStderr()
580 } 549 }
581 else 550 else
582 rv = false; 551 rv = false;
583 return rv; 552 return rv;
584} 553}
585 554
586
587/////////////////////////////
588// protected slots //
589/////////////////////////////
590
591
592
593void OProcess::slotChildOutput(int fdno) 555void OProcess::slotChildOutput(int fdno)
594{ 556{
595 if (!childOutput(fdno)) 557 if (!childOutput(fdno))
596 closeStdout(); 558 closeStdout();
597} 559}
598 560
599
600void OProcess::slotChildError(int fdno) 561void OProcess::slotChildError(int fdno)
601{ 562{
602 if (!childError(fdno)) 563 if (!childError(fdno))
603 closeStderr(); 564 closeStderr();
604} 565}
605 566
606
607void OProcess::slotSendData(int) 567void OProcess::slotSendData(int)
608{ 568{
609 if (input_sent == input_total) 569 if (input_sent == input_total)
610 { 570 {
611 innot->setEnabled(false); 571 innot->setEnabled(false);
612 input_data = 0; 572 input_data = 0;
613 emit wroteStdin(this); 573 emit wroteStdin(this);
614 } 574 }
615 else 575 else
616 input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent); 576 input_sent += ::write(in[1], input_data+input_sent, input_total-input_sent);
617} 577}
618 578
619
620
621//////////////////////////////
622// private member functions //
623//////////////////////////////
624
625
626
627void OProcess::processHasExited(int state) 579void OProcess::processHasExited(int state)
628{ 580{
629 if (runs) 581 if (runs)
630 { 582 {
631 runs = false; 583 runs = false;
632 status = state; 584 status = state;
@@ -638,14 +590,12 @@ void OProcess::processHasExited(int state)
638 { 590 {
639 emit processExited(this); 591 emit processExited(this);
640 } 592 }
641 } 593 }
642} 594}
643 595
644
645
646int OProcess::childOutput(int fdno) 596int OProcess::childOutput(int fdno)
647{ 597{
648 if (communication & NoRead) 598 if (communication & NoRead)
649 { 599 {
650 int len = -1; 600 int len = -1;
651 emit receivedStdout(fdno, len); 601 emit receivedStdout(fdno, len);
@@ -664,28 +614,24 @@ int OProcess::childOutput(int fdno)
664 emit receivedStdout(this, buffer, len); 614 emit receivedStdout(this, buffer, len);
665 } 615 }
666 return len; 616 return len;
667 } 617 }
668} 618}
669 619
670
671
672int OProcess::childError(int fdno) 620int OProcess::childError(int fdno)
673{ 621{
674 char buffer[1024]; 622 char buffer[1024];
675 int len; 623 int len;
676 624
677 len = ::read(fdno, buffer, 1024); 625 len = ::read(fdno, buffer, 1024);
678 626
679 if ( 0 < len) 627 if ( 0 < len)
680 emit receivedStderr(this, buffer, len); 628 emit receivedStderr(this, buffer, len);
681 return len; 629 return len;
682} 630}
683 631
684
685
686int OProcess::setupCommunication(Communication comm) 632int OProcess::setupCommunication(Communication comm)
687{ 633{
688 int ok; 634 int ok;
689 635
690 communication = comm; 636 communication = comm;
691 637
@@ -699,14 +645,12 @@ int OProcess::setupCommunication(Communication comm)
699 if (comm & Stderr) 645 if (comm & Stderr)
700 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0; 646 ok &= socketpair(AF_UNIX, SOCK_STREAM, 0, err) >= 0;
701 647
702 return ok; 648 return ok;
703} 649}
704 650
705
706
707int OProcess::commSetupDoneP() 651int OProcess::commSetupDoneP()
708{ 652{
709 int ok = 1; 653 int ok = 1;
710 654
711 if (communication != NoCommunication) 655 if (communication != NoCommunication)
712 { 656 {
@@ -716,13 +660,14 @@ int OProcess::commSetupDoneP()
716 close(out[1]); 660 close(out[1]);
717 if (communication & Stderr) 661 if (communication & Stderr)
718 close(err[1]); 662 close(err[1]);
719 663
720 // Don't create socket notifiers and set the sockets non-blocking if 664 // Don't create socket notifiers and set the sockets non-blocking if
721 // blocking is requested. 665 // blocking is requested.
722 if (run_mode == Block) return ok; 666 if ( run_mode == Block )
667 return ok;
723 668
724 if (communication & Stdin) 669 if (communication & Stdin)
725 { 670 {
726 // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); 671 // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK));
727 innot = new QSocketNotifier(in[1], QSocketNotifier::Write, this); 672 innot = new QSocketNotifier(in[1], QSocketNotifier::Write, this);
728 CHECK_PTR(innot); 673 CHECK_PTR(innot);
@@ -751,14 +696,12 @@ int OProcess::commSetupDoneP()
751 this, SLOT(slotChildError(int))); 696 this, SLOT(slotChildError(int)));
752 } 697 }
753 } 698 }
754 return ok; 699 return ok;
755} 700}
756 701
757
758
759int OProcess::commSetupDoneC() 702int OProcess::commSetupDoneC()
760{ 703{
761 int ok = 1; 704 int ok = 1;
762 struct linger so; 705 struct linger so;
763 memset(&so, 0, sizeof(so)); 706 memset(&so, 0, sizeof(so));
764 707
@@ -799,14 +742,12 @@ int OProcess::commSetupDoneC()
799 ok &= dup2( null_fd, STDERR_FILENO ) != -1; 742 ok &= dup2( null_fd, STDERR_FILENO ) != -1;
800 close( null_fd ); 743 close( null_fd );
801 } 744 }
802 return ok; 745 return ok;
803} 746}
804 747
805
806
807void OProcess::commClose() 748void OProcess::commClose()
808{ 749{
809 if (NoCommunication != communication) 750 if (NoCommunication != communication)
810 { 751 {
811 bool b_in = (communication & Stdin); 752 bool b_in = (communication & Stdin);
812 bool b_out = (communication & Stdout); 753 bool b_out = (communication & Stdout);
@@ -862,26 +803,29 @@ void OProcess::commClose()
862 FD_SET(out[0], &rfds); 803 FD_SET(out[0], &rfds);
863 804
864 if (b_err) 805 if (b_err)
865 FD_SET(err[0], &rfds); 806 FD_SET(err[0], &rfds);
866 807
867 fds_ready = select(max_fd+1, &rfds, 0, 0, p_timeout); 808 fds_ready = select(max_fd+1, &rfds, 0, 0, p_timeout);
868 if (fds_ready <= 0) break; 809 if ( fds_ready <= 0 )
810 break;
869 811
870 if (b_out && FD_ISSET(out[0], &rfds)) 812 if (b_out && FD_ISSET(out[0], &rfds))
871 { 813 {
872 int ret = 1; 814 int ret = 1;
873 while (ret > 0) ret = childOutput(out[0]); 815 while ( ret > 0 )
816 ret = childOutput( out[ 0 ] );
874 if ((ret == -1 && errno != EAGAIN) || ret == 0) 817 if ((ret == -1 && errno != EAGAIN) || ret == 0)
875 b_out = false; 818 b_out = false;
876 } 819 }
877 820
878 if (b_err && FD_ISSET(err[0], &rfds)) 821 if (b_err && FD_ISSET(err[0], &rfds))
879 { 822 {
880 int ret = 1; 823 int ret = 1;
881 while (ret > 0) ret = childError(err[0]); 824 while ( ret > 0 )
825 ret = childError( err[ 0 ] );
882 if ((ret == -1 && errno != EAGAIN) || ret == 0) 826 if ((ret == -1 && errno != EAGAIN) || ret == 0)
883 b_err = false; 827 b_err = false;
884 } 828 }
885 } 829 }
886 } 830 }
887 831
@@ -935,17 +879,19 @@ QCString OProcess::searchShell()
935} 879}
936 880
937bool OProcess::isExecutable(const QCString &filename) 881bool OProcess::isExecutable(const QCString &filename)
938{ 882{
939 struct stat fileinfo; 883 struct stat fileinfo;
940 884
941 if (filename.isEmpty()) return false; 885 if ( filename.isEmpty() )
886 return false;
942 887
943 // CC: we've got a valid filename, now let's see whether we can execute that file 888 // CC: we've got a valid filename, now let's see whether we can execute that file
944 889
945 if (-1 == stat(filename.data(), &fileinfo)) return false; 890 if ( -1 == stat( filename.data(), &fileinfo ) )
891 return false;
946 // CC: return false if the file does not exist 892 // CC: return false if the file does not exist
947 893
948 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets 894 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
949 if ( (S_ISDIR(fileinfo.st_mode)) || 895 if ( (S_ISDIR(fileinfo.st_mode)) ||
950 (S_ISCHR(fileinfo.st_mode)) || 896 (S_ISCHR(fileinfo.st_mode)) ||
951 (S_ISBLK(fileinfo.st_mode)) || 897 (S_ISBLK(fileinfo.st_mode)) ||
@@ -957,14 +903,13 @@ bool OProcess::isExecutable(const QCString &filename)
957 (S_ISDIR(fileinfo.st_mode)) ) 903 (S_ISDIR(fileinfo.st_mode)) )
958 { 904 {
959 return false; 905 return false;
960 } 906 }
961 907
962 // CC: now check for permission to execute the file 908 // CC: now check for permission to execute the file
963 if (access(filename.data(), X_OK) != 0) return false; 909 if ( access( filename.data(), X_OK ) != 0 )
910 return false;
964 911
965 // CC: we've passed all the tests... 912 // CC: we've passed all the tests...
966 return true; 913 return true;
967} 914}
968 915
969
970
diff --git a/libopie2/opiecore/oprocess.h b/libopie2/opiecore/oprocess.h
index 8dd19b5..352485b 100644
--- a/libopie2/opiecore/oprocess.h
+++ b/libopie2/opiecore/oprocess.h
@@ -1,45 +1,49 @@
1/* This file is part of the KDE libraries 1/*
2 Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) 2                This file is part of the Opie Project
3 3             Copyright (C) 2003-2004 Holger Freyther <zecke@handhelds.org>
4 This library is free software; you can redistribute it and/or 4 Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 modify it under the terms of the GNU Library General Public 5 =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at)
6 License as published by the Free Software Foundation; either 6 .=l.
7 version 2 of the License, or (at your option) any later version. 7          .>+-=
8 8_;:,     .>    :=|. This program is free software; you can
9 This library is distributed in the hope that it will be useful, 9.> <`_,   >  .   <= redistribute it and/or modify it under
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11.="- .-=="i,     .._ License as published by the Free Software
12 Library General Public License for more details. 12- .   .-<_>     .<> Foundation; either version 2 of the License,
13 13    ._= =}       : or (at your option) any later version.
14 You should have received a copy of the GNU Library General Public License 14   .%`+i>       _;_.
15 along with this library; see the file COPYING.LIB. If not, write to 15   .i_,=:_.      -<s. This program is distributed in the hope that
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17   : ..    .:,     . . . without even the implied warranty of
18   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22:     =  ...= . :.=-
23-.   .:....=;==+<; You should have received a copy of the GNU
24 -_. . .   )=.  = Library General Public License along with
25   --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
18*/ 29*/
19//
20// KPROCESS -- A class for handling child processes in KDE without
21// having to take care of Un*x specific implementation details
22//
23// version 0.3.1, Jan 8th 1998
24//
25// (C) Christian Czezatke
26// e9025461@student.tuwien.ac.at
27// Ported by Holger Freyther to the Open Palmtop Integrated Environment
28//
29 30
30#ifndef __kprocess_h__ 31#ifndef OPROCESS_H
31#define __kprocess_h__ 32#define OPROCESS_H
33
34/* QT */
35#include <qcstring.h>
36#include <qobject.h>
37#include <qvaluelist.h>
32 38
39/* STD */
33#include <sys/types.h> // for pid_t 40#include <sys/types.h> // for pid_t
34#include <sys/wait.h> 41#include <sys/wait.h>
35#include <signal.h> 42#include <signal.h>
36#include <unistd.h> 43#include <unistd.h>
37#include <qvaluelist.h>
38#include <qcstring.h>
39#include <qobject.h>
40 44
41class QSocketNotifier; 45class QSocketNotifier;
42class OProcessPrivate; 46class OProcessPrivate;
43 47
44/** 48/**
45 * Child process invocation, monitoring and control. 49 * Child process invocation, monitoring and control.
@@ -138,13 +142,13 @@ class OProcessPrivate;
138 *@li void @ref wroteStdin(OProcess *proc); 142 *@li void @ref wroteStdin(OProcess *proc);
139 *@li -- Indicates that all data that has been sent to the child process 143 *@li -- Indicates that all data that has been sent to the child process
140 *by a prior call to @ref writeStdin() has actually been transmitted to the 144 *by a prior call to @ref writeStdin() has actually been transmitted to the
141 *client . 145 *client .
142 * 146 *
143 *@author Christian Czezakte e9025461@student.tuwien.ac.at 147 *@author Christian Czezakte e9025461@student.tuwien.ac.at
144 * 148 *@author Holger Freyther (Opie Port)
145 * 149 *
146 **/ 150 **/
147class OProcess : public QObject 151class OProcess : public QObject
148{ 152{
149 Q_OBJECT 153 Q_OBJECT
150 154
@@ -392,13 +396,16 @@ public:
392 bool closeStderr(); 396 bool closeStderr();
393 397
394 /** 398 /**
395 * Lets you see what your arguments are for debugging. 399 * Lets you see what your arguments are for debugging.
396 */ 400 */
397 401
398 const QValueList<QCString> &args() { return arguments; } 402 const QValueList<QCString> &args()
403 {
404 return arguments;
405 }
399 406
400 /** 407 /**
401 * Controls whether the started process should drop any 408 * Controls whether the started process should drop any
402 * setuid/segid privileges or whether it should keep them 409 * setuid/segid privileges or whether it should keep them
403 * 410 *
404 * The default is @p false : drop privileges 411 * The default is @p false : drop privileges
@@ -451,14 +458,12 @@ public:
451 * Deleting the OProcess will no longer kill the child process. 458 * Deleting the OProcess will no longer kill the child process.
452 * Note that the current process remains the parent process of the 459 * Note that the current process remains the parent process of the
453 * child process. 460 * child process.
454 */ 461 */
455 void detach(); 462 void detach();
456 463
457
458
459signals: 464signals:
460 465
461 /** 466 /**
462 * Emitted after the process has terminated when 467 * Emitted after the process has terminated when
463 * the process was run in the @p NotifyOnExit (==default option to 468 * the process was run in the @p NotifyOnExit (==default option to
464 * @ref start()) or the @ref Block mode. 469 * @ref start()) or the @ref Block mode.
@@ -519,13 +524,12 @@ signals:
519 * Emitted after all the data that has been 524 * Emitted after all the data that has been
520 * specified by a prior call to @ref writeStdin() has actually been 525 * specified by a prior call to @ref writeStdin() has actually been
521 * written to the child process. 526 * written to the child process.
522 **/ 527 **/
523 void wroteStdin(OProcess *proc); 528 void wroteStdin(OProcess *proc);
524 529
525
526protected slots: 530protected slots:
527 531
528 /** 532 /**
529 * This slot gets activated when data from the child's stdout arrives. 533 * This slot gets activated when data from the child's stdout arrives.
530 * It usually calls "childOutput" 534 * It usually calls "childOutput"
531 */ 535 */
@@ -706,13 +710,12 @@ protected:
706 /** 710 /**
707 * @ref OProcessController is a friend of OProcess because it has to have 711 * @ref OProcessController is a friend of OProcess because it has to have
708 * access to various data members. 712 * access to various data members.
709 */ 713 */
710 friend class OProcessController; 714 friend class OProcessController;
711 715
712
713private: 716private:
714 /** 717 /**
715 * Searches for a valid shell. 718 * Searches for a valid shell.
716 * Here is the algorithm used for finding an executable shell: 719 * Here is the algorithm used for finding an executable shell:
717 * 720 *
718 * @li Try the executable pointed to by the "SHELL" environment 721 * @li Try the executable pointed to by the "SHELL" environment
@@ -734,14 +737,11 @@ private:
734 // Disallow assignment and copy-construction 737 // Disallow assignment and copy-construction
735 OProcess( const OProcess& ); 738 OProcess( const OProcess& );
736 OProcess& operator= ( const OProcess& ); 739 OProcess& operator= ( const OProcess& );
737 740
738private: 741private:
739 void init ( ); 742 void init ( );
740
741 OProcessPrivate *d; 743 OProcessPrivate *d;
742}; 744};
743 745
744
745
746#endif 746#endif
747 747