common.c (9c3a985f88fa4de82bf4bda906095ce6444e9039) | common.c (2a36c26fe3b8e2cf39e15e80ba1abc889a75da4f) |
---|---|
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */ 3 4#ifndef _GNU_SOURCE 5#define _GNU_SOURCE 6#endif 7#include <ctype.h> 8#include <errno.h> --- 54 unchanged lines hidden (view full) --- 63 return; 64 65 va_start(ap, fmt); 66 vfprintf(stderr, fmt, ap); 67 fprintf(stderr, "\n"); 68 va_end(ap); 69} 70 | 1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */ 3 4#ifndef _GNU_SOURCE 5#define _GNU_SOURCE 6#endif 7#include <ctype.h> 8#include <errno.h> --- 54 unchanged lines hidden (view full) --- 63 return; 64 65 va_start(ap, fmt); 66 vfprintf(stderr, fmt, ap); 67 fprintf(stderr, "\n"); 68 va_end(ap); 69} 70 |
71static bool is_bpffs(char *path) | 71static bool is_bpffs(const char *path) |
72{ 73 struct statfs st_fs; 74 75 if (statfs(path, &st_fs) < 0) 76 return false; 77 78 return (unsigned long)st_fs.f_type == BPF_FS_MAGIC; 79} --- 159 unchanged lines hidden (view full) --- 239 p_err("incorrect object type: %s", get_fd_type_name(type)); 240 close(fd); 241 return -1; 242 } 243 244 return fd; 245} 246 | 72{ 73 struct statfs st_fs; 74 75 if (statfs(path, &st_fs) < 0) 76 return false; 77 78 return (unsigned long)st_fs.f_type == BPF_FS_MAGIC; 79} --- 159 unchanged lines hidden (view full) --- 239 p_err("incorrect object type: %s", get_fd_type_name(type)); 240 close(fd); 241 return -1; 242 } 243 244 return fd; 245} 246 |
247int mount_bpffs_for_pin(const char *name) | 247int mount_bpffs_for_pin(const char *name, bool is_dir) |
248{ 249 char err_str[ERR_MAX_LEN]; 250 char *file; 251 char *dir; 252 int err = 0; 253 | 248{ 249 char err_str[ERR_MAX_LEN]; 250 char *file; 251 char *dir; 252 int err = 0; 253 |
254 if (is_dir && is_bpffs(name)) 255 return err; 256 |
|
254 file = malloc(strlen(name) + 1); 255 if (!file) { 256 p_err("mem alloc failed"); 257 return -1; 258 } 259 260 strcpy(file, name); 261 dir = dirname(file); --- 19 unchanged lines hidden (view full) --- 281 free(file); 282 return err; 283} 284 285int do_pin_fd(int fd, const char *name) 286{ 287 int err; 288 | 257 file = malloc(strlen(name) + 1); 258 if (!file) { 259 p_err("mem alloc failed"); 260 return -1; 261 } 262 263 strcpy(file, name); 264 dir = dirname(file); --- 19 unchanged lines hidden (view full) --- 284 free(file); 285 return err; 286} 287 288int do_pin_fd(int fd, const char *name) 289{ 290 int err; 291 |
289 err = mount_bpffs_for_pin(name); | 292 err = mount_bpffs_for_pin(name, false); |
290 if (err) 291 return err; 292 293 err = bpf_obj_pin(fd, name); 294 if (err) 295 p_err("can't pin the object (%s): %s", name, strerror(errno)); 296 297 return err; --- 810 unchanged lines hidden --- | 293 if (err) 294 return err; 295 296 err = bpf_obj_pin(fd, name); 297 if (err) 298 p_err("can't pin the object (%s): %s", name, strerror(errno)); 299 300 return err; --- 810 unchanged lines hidden --- |