https://github.com/git/git
Revision 4bd481e0ad9c6e78e320288886ffdad8f76dcfc1 authored by Jeff King on 17 January 2023, 03:04:44 UTC, committed by Johannes Schindelin on 06 February 2023, 08:27:09 UTC
The IOCTLFUNCTION option has been deprecated, and generates a compiler
warning in recent versions of curl. We can switch to using SEEKFUNCTION
instead. It was added in 2008 via curl 7.18.0; our INSTALL file already
indicates we require at least curl 7.19.4.

But there's one catch: curl says we should use CURL_SEEKFUNC_{OK,FAIL},
and those didn't arrive until 7.19.5. One workaround would be to use a
bare 0/1 here (or define our own macros).  But let's just bump the
minimum required version to 7.19.5. That version is only a minor version
bump from our existing requirement, and is only a 2 month time bump for
versions that are almost 13 years old. So it's not likely that anybody
cares about the distinction.

Switching means we have to rewrite the ioctl functions into seek
functions. In some ways they are simpler (seeking is the only
operation), but in some ways more complex (the ioctl allowed only a full
rewind, but now we can seek to arbitrary offsets).

Curl will only ever use SEEK_SET (per their documentation), so I didn't
bother implementing anything else, since it would naturally be
completely untested. This seems unlikely to change, but I added an
assertion just in case.

Likewise, I doubt curl will ever try to seek outside of the buffer sizes
we've told it, but I erred on the defensive side here, rather than do an
out-of-bounds read.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4fab049
Raw File
Tip revision: 4bd481e0ad9c6e78e320288886ffdad8f76dcfc1 authored by Jeff King on 17 January 2023, 03:04:44 UTC
http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
Tip revision: 4bd481e
sigchain.h
#ifndef SIGCHAIN_H
#define SIGCHAIN_H

/**
 * Code often wants to set a signal handler to clean up temporary files or
 * other work-in-progress when we die unexpectedly. For multiple pieces of
 * code to do this without conflicting, each piece of code must remember
 * the old value of the handler and restore it either when:
 *
 *   1. The work-in-progress is finished, and the handler is no longer
 *      necessary. The handler should revert to the original behavior
 *      (either another handler, SIG_DFL, or SIG_IGN).
 *
 *   2. The signal is received. We should then do our cleanup, then chain
 *      to the next handler (or die if it is SIG_DFL).
 *
 * Sigchain is a tiny library for keeping a stack of handlers. Your handler
 * and installation code should look something like:
 *
 * ------------------------------------------
 *   void clean_foo_on_signal(int sig)
 *   {
 * 	  clean_foo();
 * 	  sigchain_pop(sig);
 * 	  raise(sig);
 *   }
 *
 *   void other_func()
 *   {
 * 	  sigchain_push_common(clean_foo_on_signal);
 * 	  mess_up_foo();
 * 	  clean_foo();
 *   }
 * ------------------------------------------
 *
 */

/**
 * Handlers are given the typedef of sigchain_fun. This is the same type
 * that is given to signal() or sigaction(). It is perfectly reasonable to
 * push SIG_DFL or SIG_IGN onto the stack.
 */
typedef void (*sigchain_fun)(int);

/* You can sigchain_push and sigchain_pop individual signals. */
int sigchain_push(int sig, sigchain_fun f);
int sigchain_pop(int sig);

/**
 * push the handler onto the stack for the common signals:
 * SIGINT, SIGHUP, SIGTERM, SIGQUIT and SIGPIPE.
 */
void sigchain_push_common(sigchain_fun f);

void sigchain_pop_common(void);

#endif /* SIGCHAIN_H */
back to top