Creating a socket and setting up a connection with the server(daemon). Signed-off-by: Janani Venkataraman <jananive@xxxxxxxxxxxxxxxxxx> --- src/Makefile.am | 4 +++ src/client.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/client.c diff --git a/src/Makefile.am b/src/Makefile.am index b9b2e9b..a1d57ca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,10 @@ HAVE_SYSTEMD_SOCKET_SUPPORT = 0 SOCKET_PATH = /var/run/gencored.socket CFLAGS += -I. -DHAVE_SYSTEMD_SOCKET_SUPPORT='$(HAVE_SYSTEMD_SOCKET_SUPPORT)' -DSOCKET_PATH='"$(SOCKET_PATH)"' +lib_LTLIBRARIES = libgencore.la +libgencore_la_LDFLAGS = -fPIC +libgencore_la_SOURCES = client.c + bin_PROGRAMS = gencore gencore_SOURCES = coredump.c proc.c elf32.c elf64.c diff --git a/src/client.c b/src/client.c new file mode 100644 index 0000000..cddaf94 --- /dev/null +++ b/src/client.c @@ -0,0 +1,70 @@ +/* + * Client interface for selfdump. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) IBM Corporation, 2013 + * + * Authors: + * Janani Venkataraman <jananve@xxxxxxxxxx> + */ + +#include <stdio.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> + +int setup_connection(void) +{ + int socket_fd; + struct sockaddr_un address; + socklen_t len = sizeof(struct sockaddr_un); + + /* Creating the socket */ + socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); + if (socket_fd < 0) + return -1; + + memset(&address, 0, len); + + address.sun_family = PF_FILE; + strcpy(address.sun_path, SOCKET_PATH); + + /* Connecting to the server */ + if (connect(socket_fd, (struct sockaddr *) &address, len)) { + close(socket_fd); + return -1; + } + + return socket_fd; +} + +int gencore(char *corefile) +{ + int socket, ret; + + /* Socket operation */ + socket = setup_connection(); + if (socket == -1) { + ret = errno; + goto cleanup; + } + +cleanup: + + return ret; +} -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html