| 1927 | */ |
| 1928 | |
| 1929 | int /* O - 1 on success, 0 on failure */ |
| 1930 | cupsdSendCommand( |
| 1931 | cupsd_client_t *con, /* I - Client connection */ |
| 1932 | char *command, /* I - Command to run */ |
| 1933 | char *options, /* I - Command-line options */ |
| 1934 | int root) /* I - Run as root? */ |
| 1935 | { |
| 1936 | int fd; /* Standard input file descriptor */ |
| 1937 | |
| 1938 | |
| 1939 | if (con->filename) |
| 1940 | { |
| 1941 | fd = open(con->filename, O_RDONLY); |
| 1942 | |
| 1943 | if (fd < 0) |
| 1944 | { |
| 1945 | cupsdLogClient(con, CUPSD_LOG_ERROR, |
| 1946 | "Unable to open \"%s\" for reading: %s", |
| 1947 | con->filename ? con->filename : "/dev/null", |
| 1948 | strerror(errno)); |
| 1949 | return (0); |
| 1950 | } |
| 1951 | |
| 1952 | fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
| 1953 | } |
| 1954 | else |
| 1955 | fd = -1; |
| 1956 | |
| 1957 | con->pipe_pid = pipe_command(con, fd, &(con->file), command, options, root); |
| 1958 | con->pipe_status = HTTP_STATUS_OK; |
| 1959 | |
| 1960 | httpClearFields(con->http); |
| 1961 | |
| 1962 | if (fd >= 0) |
| 1963 | close(fd); |
| 1964 | |
| 1965 | cupsdLogClient(con, CUPSD_LOG_INFO, "Started \"%s\" (pid=%d, file=%d)", |
| 1966 | command, con->pipe_pid, con->file); |
| 1967 | |
| 1968 | if (con->pipe_pid == 0) |
| 1969 | return (0); |
| 1970 | |
| 1971 | fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC); |
| 1972 | |
| 1973 | cupsdAddSelect(con->file, (cupsd_selfunc_t)write_pipe, NULL, con); |
| 1974 | |
| 1975 | cupsdLogClient(con, CUPSD_LOG_DEBUG, "Waiting for CGI data."); |
| 1976 | |
| 1977 | con->sent_header = 0; |
| 1978 | con->file_ready = 0; |
| 1979 | con->got_fields = 0; |
| 1980 | con->header_used = 0; |
| 1981 | |
| 1982 | return (1); |
| 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | /* |
no test coverage detected