bsd

Use OpenBSD's malloc, realloc and free in my program

柔情痞子 提交于 2019-12-23 09:29:47
问题 I would like to use OpenBSD's implementation of malloc, realloc and free on my Debian lenny desktop rather than glibc's. Are they simply drop in replacements: will they work on my Linux desktop ? Which are the file(s) that I need and which OpenBSD package contains them ? 回答1: Google has their own malloc replacement library at http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools with instructions for using it. They say all you need to do is link it in (before the standard

Failed to execute script.sh: unknown error

大城市里の小女人 提交于 2019-12-22 17:19:00
问题 I wanted to use DTrace to see "what syscalls are made by my shell script". I made a very simple shell script, shell.sh , and gave it execute privileges: #!/bin/bash grep 1 <<< 123 I cd 'd into its directory, and ran this simple DTrace script: sudo dtrace -n 'syscall:::entry /pid == $target/ { @[probefunc] = count(); }' -c ./trace-me.sh I get this error output: dtrace: failed to execute ./trace-me.sh: unknown error What happened here? I've run csrutil enable --without dtrace . The DTrace

Get Current User from root mode?

北慕城南 提交于 2019-12-21 22:26:02
问题 I am writing a login item and I am trying to find if its possible to get the current user. Lets say, I have logged in with user "Test" and when I execute the exe with root privileges and if I use char *user = getenv("USER"); user is "root". My expected answer is "Test". How can I get it? I don't know if I can put objective c code in login item? Is it possible to NSUserName in login item. NSString *user = NSUserName(); 回答1: You want the SCDynamicStoreCopyConsoleUser function. QA1133 gives some

How can I detect BSD vs. GNU version of date in shell script

僤鯓⒐⒋嵵緔 提交于 2019-12-20 10:27:23
问题 I am writing a shell script that needs to do some date string manipulation. The script should work across as many *nix variants as possible, so I need to handle situations where the machine might have the BSD or the GNU version of date. What would be the most elegant way to test for the OS type, so I can send the correct date flags? EDIT: To clarify, my goal is to use date's relative date calculation tools which seem distinct in BSD and GNU. BSD example date -v -1d GNU example date --date="1

Non-greedy matching with grep

瘦欲@ 提交于 2019-12-19 17:38:09
问题 Non greedy matching as far as I know is not part of Basic Regular Expression (BRE) and Extended Regular Expression (ERE). However, the behaviour on different versions of grep (BSD and GNU) seems to suggest other wise. For example, let's take the following example. I have a string say: string="hello_my_dear_polo" Using GNU grep : Following are few attempts to extract hello from the string. BRE Attempt (fails) : $ grep -o "hel.*\?o" <<< "$string" hello_my_dear_polo Output yields entire string

UDP broadcast using CFSocket on IOS

你说的曾经没有我的故事 提交于 2019-12-19 07:53:34
问题 Have been doing some google search and some reading on this subject but cannot seem to get it right no matter how much time i spent searching. What i want to do is to receive broadcast message of devices that are connected on my network by advertising my interest in their services that they supply. Using wireshark i can see the broadcast/notification messages from the network devices that i want to connect to sent over my network but not my broadcast search for interest of their services. But

UDP broadcast using CFSocket on IOS

馋奶兔 提交于 2019-12-19 07:53:00
问题 Have been doing some google search and some reading on this subject but cannot seem to get it right no matter how much time i spent searching. What i want to do is to receive broadcast message of devices that are connected on my network by advertising my interest in their services that they supply. Using wireshark i can see the broadcast/notification messages from the network devices that i want to connect to sent over my network but not my broadcast search for interest of their services. But

Is it possible that `fileno(stdout) != 1` on a POSIX system?

余生长醉 提交于 2019-12-19 06:45:14
问题 Can stdout file descriptor differ from 1 (STDOUT_FILENO) assuming stdout need not be a modifiable lvalue? For example, can freopen("/dev/null", "w", stdout) change fileno(stdout) result? 回答1: Yes. Test program: #include <stdio.h> int main() { fclose(stdin); freopen("stdout.txt", "w+", stdout); fprintf(stderr, "%d\n", fileno(stdout)); return 0; } This prints 0 on my machine (OS X 10.9.4). File descriptors are typically reused starting from the lowest number first. By closing stdin , file

Is it possible that `fileno(stdout) != 1` on a POSIX system?

南笙酒味 提交于 2019-12-19 06:44:09
问题 Can stdout file descriptor differ from 1 (STDOUT_FILENO) assuming stdout need not be a modifiable lvalue? For example, can freopen("/dev/null", "w", stdout) change fileno(stdout) result? 回答1: Yes. Test program: #include <stdio.h> int main() { fclose(stdin); freopen("stdout.txt", "w+", stdout); fprintf(stderr, "%d\n", fileno(stdout)); return 0; } This prints 0 on my machine (OS X 10.9.4). File descriptors are typically reused starting from the lowest number first. By closing stdin , file

Detecting a chroot jail from within

吃可爱长大的小学妹 提交于 2019-12-18 10:36:08
问题 How can one detect being in a chroot jail without root privileges? Assume a standard BSD or Linux system. The best I came up with was to look at the inode value for "/" and to consider whether it is reasonably low, but I would like a more accurate method for detection. [edit 20080916 142430 EST] Simply looking around the filesystem isn't sufficient, as it's not difficult to duplicate things like /boot and /dev to fool the jailed user. [edit 20080916 142950 EST] For Linux systems, checking for