Commit Graph

22 Commits

Author SHA1 Message Date
Ben Noordhuis
75c8850c91 darwin: fix build with non-apple compilers
The header files for ApplicationServices and CoreFoundation contain
C language extensions that Apple's compiler understands but gcc does
not, notably blocks:

https://en.wikipedia.org/wiki/Blocks_(C_language_extension)

Work around that by defining the types inline and stop including
the headers. It's inelegant but the alternatives are worse.

Fixes: https://github.com/libuv/libuv/issues/2805
PR-URL: https://github.com/libuv/libuv/pull/2811
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-04-28 20:07:59 +02:00
Ben Noordhuis
6e3e422c2d darwin: stop calling SetApplicationIsDaemon()
It's been reported that calling this function causes the Core Graphics
framework to start reporting bogus values.

Commit 565cdd16 ('Revert "darwin: speed up uv_set_process_title()"')
attempted to fix this but apparently merely postponed the moment
when `CGDisplayPixelsWide()` and friends start reporting bogus values.

The Chromium code base mentions that calling `SetApplicationIsDaemon()`
prevents the HIServices framework from terminating the process when it
can't connect to launchservicesd.

Libuv itself doesn't use HIServices but it's possible that the libuv
user does. If said user doesn't call `SetApplicationIsDaemon()`, it's
possible this commit introduces an observable change in behavior.

The `SetApplicationIsDaemon()` call was introduced in commit 08e0e63f
("darwin: avoid calling GetCurrentProcess") from October 2013 to work
around a bug in macos 10.9 where the Activity Monitor showed the program
as "Not responding."

Fixes: https://github.com/libuv/libuv/issues/2566 (for real, hopefully)
Fixes: https://github.com/nodejs/node/issues/31328
PR-URL: https://github.com/libuv/libuv/pull/2593
Refs: https://cs.chromium.org/chromium/src/sandbox/mac/system_services.cc?l=26&rcl=a06d2fe5a279ddecd358d919d461080e2c53c92e
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-01-21 09:25:49 +01:00
Ben Noordhuis
d077d066fd darwin: assume pthread_setname_np() is available
Stop dlsym-ing the symbol name at run-time, that was only necessary to
support macOS and iOS versions that were already near-obsolete when this
feature was introduced in August 2013.

This reapplies commit bee1bf5dd7 from October.

PR-URL: https://github.com/libuv/libuv/pull/2568
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2019-12-16 15:22:25 +01:00
Ben Noordhuis
565cdd16bb Revert "darwin: speed up uv_set_process_title()"
This reverts commit 038eacfbf4.

It was reported that this change causes a regression when trying
to obtain the screen resolution with `CGDisplayPixelsWide()` or
`CGDisplayPixelsHigh()` after changing the process title.

This is the second time this change had to be reverted due to
regressions and, although third time is allegedly the charm,
leaving well enough alone is the proverb I plan to adhere to...

Fixes: https://github.com/libuv/libuv/issues/2566
PR-URL: https://github.com/libuv/libuv/pull/2568
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2019-12-16 15:22:25 +01:00
Ben Noordhuis
56f8366873 Revert "darwin: assume pthread_setname_np() is available"
This reverts commit bee1bf5dd7.

This is necessary in order to be able to revert commit 038eacfbf4
("darwin: speed up uv_set_process_title()") from October.

PR-URL: https://github.com/libuv/libuv/pull/2568
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2019-12-16 15:21:34 +01:00
Ben Noordhuis
bee1bf5dd7 darwin: assume pthread_setname_np() is available
Stop dlsym-ing the symbol name at run-time, that was only necessary to
support macOS and iOS versions that were already near-obsolete when this
feature was introduced in August 2013.

PR-URL: https://github.com/libuv/libuv/pull/2480
Reviewed-By: Saúl Ibarra Corretgé <s@saghul.net>
2019-10-08 12:50:26 +02:00
Ben Noordhuis
038eacfbf4 darwin: speed up uv_set_process_title()
Libuv loaded and unloaded the Core Services and Application Services for
every call to uv_set_process_title().

Change that to load them on the first call to uv_set_process_title() and
delay unloading until libuv is unloaded.

Speeds up process_title_threadsafe by about 10x on my system. It should
fail less often (hopefully not at all) on the CI now.

PR-URL: https://github.com/libuv/libuv/pull/2480
Reviewed-By: Saúl Ibarra Corretgé <s@saghul.net>
2019-10-08 12:49:47 +02:00
Ben Noordhuis
97e86dde84 Revert "darwin: speed up uv_set_process_title()"
This reverts commit 00c6b1649d.

It's been reported (and I can confirm) that this change breaks
`process.title = 'foo'` in Node.js.

Since libuv just calls out to Core Services and Application Services,
and since those frameworks are really just black boxes that you can't
look inside, it's impossible to debug what exactly goes wrong. Revert
it is then.

Fixes: https://github.com/nodejs/node/issues/28945
PR-URL: https://github.com/libuv/libuv/pull/2405
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2019-08-03 21:23:43 +02:00
Ben Noordhuis
8972e65bf5 unix: harden string copying, introduce strscpy()
Replace calls to strcpy() and strncpy() with the newly introduced
uv__strscpy() function that is meticulous about zero-terminating
the destination buffer.

PR-URL: https://github.com/libuv/libuv/pull/2065
Refs: https://www.kernel.org/doc/htmldocs/kernel-api/API-strscpy.html
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2018-12-04 17:08:09 +01:00
Ben Noordhuis
00c6b1649d darwin: speed up uv_set_process_title()
Libuv loaded and unloaded the Core Services and Application Services for
every call to uv_set_process_title().

Change that to load them on the first call to uv_set_process_title() and
delay unloading until libuv is unloaded.

Speeds up process_title_threadsafe by about 10x on my system.

PR-URL: https://github.com/libuv/libuv/pull/2064
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-11-04 18:37:56 +01:00
Mason X
89cbbc895b
include,src: introduce UV__ERR() macro
Using -errno, -E**, and -pthread_function() can be
error prone, and breaks compatibility with some operating
systems that already negate errno's (e.g. Haiku).

This commit adds a UV__ERR() macro that ensures libuv
errors are negative.

Fixes: https://github.com/libuv/help/issues/39
PR-URL: https://github.com/libuv/libuv/pull/1687
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2018-02-08 22:38:02 -05:00
Ben Noordhuis
0b9ee2cf00 unix: fix long line introduced in commit 94e628fa
PR-URL: https://github.com/libuv/libuv/pull/150
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-21 13:04:50 +01:00
Ben Noordhuis
955b1806c7 unix: fix implicit declaration compiler warning
Include <string.h> explicitly to get the definition of strncpy().

Refs https://github.com/libuv/libuv/issues/138.

PR-URL: https://github.com/libuv/libuv/pull/150
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-21 13:04:28 +01:00
Recep ASLANTAS
94e628faf1 unix: fix warnings when loading functions with dlsym 2014-09-17 22:47:01 +02:00
Fedor Indutny
ab0225277b Merge branch 'v0.10'
Conflicts:
	src/unix/darwin-proctitle.c
	src/version.c
2013-10-28 20:59:10 +04:00
Fedor Indutny
08e0e63f3a darwin: avoid calling GetCurrentProcess
Use some black-magic from Apple to change process name without getting
a "Not responding" tag from Activity Manager.

fix #966
2013-10-28 20:51:50 +04:00
Ben Noordhuis
d48168afd0 darwin: remove CoreFoundation dependency
Load the required symbols at run-time rather than linking against the
CoreFoundation (and CoreServices and ApplicationServices) frameworks
at build time.

Should make integration easier for people that bundle libuv with their
own projects because they no longer have to replicate magic -framework
incantations in their top-level build system.
2013-08-27 23:58:21 +02:00
Ben Noordhuis
b03192ed6f darwin: fix ios build error
Include <errno.h> and <stdlib.h>.  They're being pulled in implicitly
on OS X but apparently that's not the case with iOS builds.

Build breakage introduced in 5ff6f85 by yours truly. Mea culpa.

Fixes #885 and #891.
2013-08-19 13:26:57 +02:00
Ben Noordhuis
5ff6f85f58 darwin: call pthread_setname_np() if available
When setting the process title, also call pthread_setname_np() when
supported (OS X >= 10.6 and iOS >= 3.2.)
2013-08-15 21:52:26 +02:00
Ben Noordhuis
3ee4d3f183 unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.

A code snippet like this one:

    if (uv_foo(loop) < 0) {
      uv_err_t err = uv_last_error(loop);
      fprintf(stderr, "%s\n", uv_strerror(err));
    }

Should be rewritten like this:

    int err = uv_foo(loop);
    if (err < 0)
      fprintf(stderr, "%s\n", uv_strerror(err));

The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
2013-07-07 09:51:00 +02:00
Ben Noordhuis
f22163c233 darwin: fix ios build, don't require ApplicationServices 2013-05-13 20:16:20 +02:00
Ben Noordhuis
9b801d551b darwin: rename darwin-getproctitle.m
Rename it to darwin-getproctitle.c, it doesn't need an Objective-C
compiler. Fix up -Wpedantic warnings about void to function pointer
casts and include <ApplicationServices/ApplicationServices.h> to get
the GetCurrentProcess() function prototype.
2013-05-02 14:10:12 +02:00