Update version to 0.16
[ust.git] / ustctl / scanning_functions.c
CommitLineData
0c89df6c
NC
1/* Copyright (C) 2011 Ericsson AB, Nils Carlson <nils.carlson@ericsson.com>
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#define _GNU_SOURCE
19#include <stdio.h>
2298f329 20#include <ust/ustctl.h>
0c89df6c
NC
21#include "usterr.h"
22
23
8b26d56b 24int parse_and_connect_pid(const char *pid_string)
0c89df6c
NC
25{
26 pid_t pid;
8b26d56b 27 int sock;
0c89df6c
NC
28
29 errno = 0;
30 pid = strtoull(pid_string, NULL, 10);
31 if (errno) {
32 perror("Failed to parse pid");
33 exit(EXIT_FAILURE);
34 }
35
8b26d56b
NC
36 sock = ustctl_connect_pid(pid);
37 if (sock < 0) {
38 perror("Failed to connect to process");
39 exit(EXIT_FAILURE);
40 }
41
42 return sock;
0c89df6c
NC
43}
44
45int scan_ch_marker(const char *channel_marker, char **channel, char **marker)
46{
47 int result;
48
49 *channel = NULL;
50 *marker = NULL;
51
52 result = sscanf(channel_marker, "%a[^/]/%as", channel, marker);
53 if (result != 2) {
54 if (errno) {
55 PERROR("Failed to read channel and marker names");
56 } else {
57 ERR("Failed to parse marker and channel names");
58 }
59 if (*channel) {
60 free(*channel);
61 }
62 if (*marker) {
63 free(*marker);
64 }
65 return -1;
66 }
67
68 return 0;
69}
70
71int scan_ch_and_num(const char *ch_num, char **channel, unsigned int *num)
72{
73 int result;
74
75 *channel = NULL;
76
77 result = sscanf(ch_num, "%a[^/]/%u", channel, num);
78 if (result != 2) {
79 if (errno) {
80 PERROR("Failed to parse channel and number");
81 } else {
82 ERR("Failed to parse channel and number");
83 }
84 if (*channel) {
85 free(*channel);
86 }
87 return -1;
88 }
89
90 return 0;
91}
This page took 0.0285 seconds and 4 git commands to generate.