console-socket.c (2834c5b149151347309948034da4d8bb86ca5fde) | console-socket.c (b14ca19cf380efbf7a96a348cc6fc81e75bf0591) |
---|---|
1/** 2 * Copyright © 2016 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 13 unchanged lines hidden (view full) --- 22#include <stdlib.h> 23#include <sys/socket.h> 24#include <sys/un.h> 25#include <sys/types.h> 26#include <unistd.h> 27 28#define CONSOLE_SOCKET_PREFIX "obmc-console" 29 | 1/** 2 * Copyright © 2016 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 13 unchanged lines hidden (view full) --- 22#include <stdlib.h> 23#include <sys/socket.h> 24#include <sys/un.h> 25#include <sys/types.h> 26#include <unistd.h> 27 28#define CONSOLE_SOCKET_PREFIX "obmc-console" 29 |
30ssize_t console_socket_path(struct sockaddr_un *addr, const char *id) | 30/* Build the socket path. */ 31ssize_t console_socket_path(socket_path_t sun_path, const char *id) |
31{ | 32{ |
32 char *sun_path; | |
33 ssize_t rc; 34 | 33 ssize_t rc; 34 |
35 sun_path = (char *)addr + sizeof(*addr) - sizeof(addr->sun_path); 36 | |
37 if (id) { | 35 if (id) { |
38 rc = snprintf(sun_path + 1, sizeof(addr->sun_path) - 1, | 36 rc = snprintf(sun_path + 1, sizeof(socket_path_t) - 1, |
39 CONSOLE_SOCKET_PREFIX ".%s", id); 40 } else { | 37 CONSOLE_SOCKET_PREFIX ".%s", id); 38 } else { |
41 rc = snprintf(sun_path + 1, sizeof(addr->sun_path) - 1, | 39 rc = snprintf(sun_path + 1, sizeof(socket_path_t) - 1, |
42 CONSOLE_SOCKET_PREFIX); 43 } 44 45 if (rc < 0) { 46 return rc; 47 } 48 | 40 CONSOLE_SOCKET_PREFIX); 41 } 42 43 if (rc < 0) { 44 return rc; 45 } 46 |
49 if ((size_t)rc > (sizeof(addr->sun_path) - 1)) { | 47 if ((size_t)rc > (sizeof(socket_path_t) - 1)) { |
50 errno = 0; 51 return -1; 52 } 53 54 sun_path[0] = '\0'; 55 56 return rc + 1 /* Capture NUL prefix */; 57} --- 17 unchanged lines hidden --- | 48 errno = 0; 49 return -1; 50 } 51 52 sun_path[0] = '\0'; 53 54 return rc + 1 /* Capture NUL prefix */; 55} --- 17 unchanged lines hidden --- |