/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" #include "socket.h" #include #include /* * Open a pipe to a shell command. The command should have the * same uid/gid as the process writing onto the slave side. * Since we store the pipe's FILE structure pointer in a static * variable, there can't be more than one pipe open at the same * time. */ static FILE *pipef= NULL; int connect_pipe(const char *address) { DBG(syslog(LOG_DEBUG, "opening pipe to '%s'", address)); if( pipef != NULL ) { syslog(LOG_ERR, "another pipe is already open"); return FAIL; } pipef = popen(address, "w"); if (pipef == NULL) { syslog(LOG_ERR, "popen: %m"); return FAIL; } /* * Since I don't need stream semantics extract the file * descriptor of the pipe here. */ return fileno(pipef); } result shutdown_pipe(int pfd) { if(pipef == NULL) { syslog(LOG_WARNING, "no pipe to shut down"); return SUCCESS; } if (pclose(pipef) == FAIL) { syslog(LOG_ERR, "pclose: %m"); pipef = NULL; return FAIL; } pipef = NULL; return SUCCESS; }