~clint-fewbar/ubuntu/precise/php5/php5-5.4-merge

« back to all changes in this revision

Viewing changes to ext/standard/proc_open.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-02-22 09:46:37 UTC
  • mfrom: (1.1.20) (0.3.18 sid)
  • Revision ID: package-import@ubuntu.com-20110222094637-nlu2tvb7oqgaarl0
Tags: 5.3.5-1ubuntu1
* Merge from debian/unstable. Remaining changes:
 - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions 
      already in universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, sybase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
    * stop mysql instance on clean just in case we failed in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
   | Author: Wez Furlong <wez@thebrainroom.com>                           |
16
16
   +----------------------------------------------------------------------+
17
17
 */
18
 
/* $Id: proc_open.c 293036 2010-01-03 09:23:27Z sebastian $ */
 
18
/* $Id: proc_open.c 303163 2010-09-08 08:34:57Z pajoye $ */
19
19
 
20
20
#if 0 && (defined(__linux__) || defined(sun) || defined(__IRIX__))
21
21
# define _BSD_SOURCE            /* linux wants this when XOPEN mode is on */
88
88
        HashPosition pos;
89
89
 
90
90
        memset(&env, 0, sizeof(env));
91
 
        
 
91
 
92
92
        if (!environment) {
93
93
                return env;
94
94
        }
95
 
        
 
95
 
96
96
        cnt = zend_hash_num_elements(Z_ARRVAL_P(environment));
97
 
        
 
97
 
98
98
        if (cnt < 1) {
99
99
#ifndef PHP_WIN32
100
100
                env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent);
112
112
        for (zend_hash_internal_pointer_reset_ex(target_hash, &pos);
113
113
                        zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS;
114
114
                        zend_hash_move_forward_ex(target_hash, &pos)) {
115
 
                
 
115
 
116
116
                convert_to_string_ex(element);
117
117
                el_len = Z_STRLEN_PP(element);
118
118
                if (el_len == 0) {
119
119
                        continue;
120
120
                }
121
 
                
 
121
 
122
122
                sizeenv += el_len+1;
123
 
                
 
123
 
124
124
                switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) {
125
125
                        case HASH_KEY_IS_STRING:
126
126
                                if (string_length == 0) {
139
139
        for (zend_hash_internal_pointer_reset_ex(target_hash, &pos);
140
140
                        zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS;
141
141
                        zend_hash_move_forward_ex(target_hash, &pos)) {
142
 
                
 
142
 
143
143
                convert_to_string_ex(element);
144
144
                el_len = Z_STRLEN_PP(element);
145
 
                
 
145
 
146
146
                if (el_len == 0) {
147
147
                        continue;
148
148
                }
149
 
                
 
149
 
150
150
                data = Z_STRVAL_PP(element);
151
151
                switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) {
152
152
                        case HASH_KEY_IS_STRING:
185
185
                                memcpy(p, string_key, string_length);
186
186
                                strcat(p, "=");
187
187
                                strcat(p, data);
188
 
                                
 
188
 
189
189
#ifndef PHP_WIN32
190
190
                                *ep = p;
191
191
                                ++ep;
203
203
                        case HASH_KEY_NON_EXISTANT:
204
204
                                break;
205
205
                }
206
 
        }       
207
 
 
208
 
        assert(p - env.envp <= sizeenv);
209
 
        
 
206
        }
 
207
 
 
208
        assert((uint)(p - env.envp) <= sizeenv);
 
209
 
210
210
        zend_hash_internal_pointer_reset_ex(target_hash, &pos);
211
211
 
212
212
        return env;
246
246
                        proc->pipes[i] = 0;
247
247
                }
248
248
        }
249
 
        
 
249
 
250
250
#ifdef PHP_WIN32
251
 
        
252
251
        WaitForSingleObject(proc->childHandle, INFINITE);
253
252
        GetExitCodeProcess(proc->childHandle, &wstatus);
254
253
        FG(pclose_ret) = wstatus;
255
254
        CloseHandle(proc->childHandle);
256
 
        
 
255
 
257
256
#elif HAVE_SYS_WAIT_H
258
 
        
 
257
 
259
258
        do {
260
259
                wait_pid = waitpid(proc->child, &wstatus, 0);
261
260
        } while (wait_pid == -1 && errno == EINTR);
262
 
        
 
261
 
263
262
        if (wait_pid == -1) {
264
263
                FG(pclose_ret) = -1;
265
264
        } else {
267
266
                        wstatus = WEXITSTATUS(wstatus);
268
267
                FG(pclose_ret) = wstatus;
269
268
        }
270
 
        
 
269
 
271
270
#else
272
271
        FG(pclose_ret) = -1;
273
272
#endif
274
273
        _php_free_envp(proc->env, proc->is_persistent);
275
274
        pefree(proc->command, proc->is_persistent);
276
275
        pefree(proc, proc->is_persistent);
277
 
        
278
276
}
279
277
/* }}} */
280
278
 
340
338
        zval *zproc;
341
339
        struct php_process_handle *proc;
342
340
        long sig_no = SIGTERM;
343
 
        
 
341
 
344
342
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zproc, &sig_no) == FAILURE) {
345
343
                RETURN_FALSE;
346
344
        }
347
345
 
348
346
        ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open);
349
 
        
 
347
 
350
348
#ifdef PHP_WIN32
351
349
        if (TerminateProcess(proc->childHandle, 255)) {
352
350
                RETURN_TRUE;
369
367
{
370
368
        zval *zproc;
371
369
        struct php_process_handle *proc;
372
 
        
 
370
 
373
371
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zproc) == FAILURE) {
374
372
                RETURN_FALSE;
375
373
        }
376
374
 
377
375
        ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open);
378
 
        
 
376
 
379
377
        zend_list_delete(Z_LVAL_P(zproc));
380
378
        RETURN_LONG(FG(pclose_ret));
381
379
}
395
393
#endif
396
394
        int running = 1, signaled = 0, stopped = 0;
397
395
        int exitcode = -1, termsig = 0, stopsig = 0;
398
 
        
 
396
 
399
397
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zproc) == FAILURE) {
400
398
                RETURN_FALSE;
401
399
        }
406
404
 
407
405
        add_assoc_string(return_value, "command", proc->command, 1);
408
406
        add_assoc_long(return_value, "pid", (long) proc->child);
409
 
        
 
407
 
410
408
#ifdef PHP_WIN32
411
 
        
 
409
 
412
410
        GetExitCodeProcess(proc->childHandle, &wstatus);
413
411
 
414
412
        running = wstatus == STILL_ACTIVE;
415
413
        exitcode = running ? -1 : wstatus;
416
 
        
 
414
 
417
415
#elif HAVE_SYS_WAIT_H
418
 
        
 
416
 
419
417
        errno = 0;
420
418
        wait_pid = waitpid(proc->child, &wstatus, WNOHANG|WUNTRACED);
421
 
        
 
419
 
422
420
        if (wait_pid == proc->child) {
423
421
                if (WIFEXITED(wstatus)) {
424
422
                        running = 0;
461
459
static inline HANDLE dup_handle(HANDLE src, BOOL inherit, BOOL closeorig)
462
460
{
463
461
        HANDLE copy, self = GetCurrentProcess();
464
 
        
 
462
 
465
463
        if (!DuplicateHandle(self, src, self, &copy, 0, inherit, DUPLICATE_SAME_ACCESS |
466
464
                                (closeorig ? DUPLICATE_CLOSE_SOURCE : 0)))
467
465
                return NULL;
553
551
                            Z_LVAL_PP(item)) {
554
552
                                suppress_errors = 1;
555
553
                        }
556
 
                }       
 
554
                }
557
555
                if (SUCCESS == zend_hash_find(Z_ARRVAL_P(other_options), "bypass_shell", sizeof("bypass_shell"), (void**)&item)) {
558
556
                        if ((Z_TYPE_PP(item) == IS_BOOL || Z_TYPE_PP(item) == IS_LONG) &&
559
557
                            Z_LVAL_PP(item)) {
560
558
                                bypass_shell = 1;
561
559
                        }
562
 
                }       
 
560
                }
563
561
        }
564
562
#endif
565
 
        
 
563
 
566
564
        command_len = strlen(command);
567
565
 
568
566
        if (environment) {
580
578
        security.bInheritHandle = TRUE;
581
579
        security.lpSecurityDescriptor = NULL;
582
580
#endif
583
 
        
 
581
 
584
582
        /* walk the descriptor spec and set up files/pipes */
585
583
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(descriptorspec), &pos);
586
584
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(descriptorspec), (void **)&descitem, &pos) == SUCCESS) {
754
752
        }
755
753
 
756
754
#ifdef PHP_WIN32
 
755
        if (cwd == NULL) {
 
756
                char cur_cwd[MAXPATHLEN];
 
757
                char *getcwd_result;
 
758
                getcwd_result = VCWD_GETCWD(cur_cwd, MAXPATHLEN);
 
759
                if (!getcwd_result) {
 
760
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot get current directory");
 
761
                        goto exit_fail;
 
762
                }
 
763
        }
 
764
 
757
765
        memset(&si, 0, sizeof(si));
758
766
        si.cb = sizeof(si);
759
767
        si.dwFlags = STARTF_USESTDHANDLES;
760
 
        
 
768
 
761
769
        si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
762
770
        si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
763
771
        si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
764
 
        
 
772
 
765
773
        /* redirect stdin/stdout/stderr if requested */
766
774
        for (i = 0; i < ndesc; i++) {
767
775
                switch(descriptors[i].index) {
777
785
                }
778
786
        }
779
787
 
780
 
        
 
788
 
781
789
        memset(&pi, 0, sizeof(pi));
782
 
        
 
790
 
783
791
        if (suppress_errors) {
784
792
                old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
785
793
        }
786
 
        
 
794
 
787
795
        dwCreateFlags = NORMAL_PRIORITY_CLASS;
788
796
        if(strcmp(sapi_module.name, "cli") != 0) {
789
797
                dwCreateFlags |= CREATE_NO_WINDOW;
795
803
                spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command);
796
804
 
797
805
                newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, dwCreateFlags, env.envp, cwd, &si, &pi);
798
 
                
 
806
 
799
807
                efree(command_with_cmd);
800
808
        }
801
809
 
802
810
        if (suppress_errors) {
803
811
                SetErrorMode(old_error_mode);
804
812
        }
805
 
        
 
813
 
806
814
        if (FALSE == newprocok) {
807
815
                DWORD dw = GetLastError();
808
816
 
887
895
                        tcsetpgrp(0, my_pid);
888
896
                }
889
897
#endif
890
 
                
 
898
 
891
899
                /* close those descriptors that we just opened for the parent stuff,
892
900
                 * dup new descriptors into required descriptors and close the original
893
901
                 * cruft */
909
917
                        close(slave_pty);
910
918
                }
911
919
#endif
912
 
                
 
920
 
913
921
                if (cwd) {
914
922
                        chdir(cwd);
915
923
                }
916
 
                
 
924
 
917
925
                if (env.envarray) {
918
926
                        execle("/bin/sh", "sh", "-c", command, NULL, env.envarray);
919
927
                } else {
1007
1015
 
1008
1016
                                        /* nasty hack; don't copy it */
1009
1017
                                        stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
1010
 
                                        
 
1018
 
1011
1019
                                        MAKE_STD_ZVAL(retfp);
1012
1020
                                        php_stream_to_zval(stream, retfp);
1013
1021
                                        add_index_zval(pipes, descriptors[i].index, retfp);