We have a site with:


Decent ranking on certain targeted keywords.
An HTTPS-only policy, which uses 302 redirects to force clients onto the secure version of any URL.
Internal links using HTTPS, so there is no redirection.
Some, but not all, external links from other domains use HTTPS. The rest do not and will of course be subject to the 302.
Google is only indexing the HTTPS version of each URL. Even if you search specifically for the HTTP URL, only the HTTPS URL is shown in the results.


Will there be any significant, immediate ranking benefit to changing our site to use 301 redirects to enforce HTTPS? Are there any statements from Google, Matt Cutts or other authorities on this specific situation?

Based on my research the difference should be minimal since we are already well indexed, and our internal links are fine, so Google is not going to apply a sitewide penalty for the 302s, which are, in effect, only the first link in the chain.


Question: UNIX semaphores
Answer: One thing to note:

sem_t *sema = mmap(NULL, sizeof(sema), 
         PROT_READ |PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (!sema) {


Failure in mmap will return MAP_FAILED, not NULL (usually I think MAP_FAILED expands to -1 cast to a pointer, meaning your failure check won't work).

As for style: This is just an opinion, but I think your style could benefit from the concept of a "cleanup block".

For example, instead of this kind of style [paraphrasing your code, not doing literal quotes]:

sema = mmap(/* ... */);

if (sema == MAP_FAILED)
{
   exit(EXIT_FAILURE);
}

foo = malloc(sizeof(*foo));
if (!foo)
{
   exit(EXIT_FAILURE);
}


You could do something like:

   int status = EXIT_FAILURE;
   sem_t *sema = NULL;
   struct foo *foo = NULL;

   sema = mmap(/* ... */);

   if (sema == MAP_FAILED)
   {
      goto cleanup;
   }

   foo = malloc(sizeof(*foo));
   if (!foo)
   {
      goto cleanup;
   }

   // TODO: do stuff with sema and foo

   // mark success
   status = EXIT_SUCCESS;

cleanup:
   if (sema &amp;&amp; sema != MAP_FAILED)
      munmap(sema, /* ... */);
   if (foo)
      free(foo);

   return status;


The benefit to this kind of style is that you can add any type of allocation you want (in between the other stuff, before it, after it, whatever), and you just need to add a quick line or two in the cleanup block, and suddenly, all success and failure paths get the resources freed.  If any of the intermediate steps fail and you wind up in the cleanup block, you can be assured that you're not leaking anything, and it won't feel repetitive to make that happen.

There are other variants of this, for example if you or someone you're working with has some religious objection to goto (even though it's the cleanest way to do error handling in plain C), on the slightly more repetitive side you could repeatedly check status to see that you're still succeeding:

int status = EXIT_SUCCESS;
sem_t *sema = NULL;
struct foo *foo = NULL;

if (status == EXIT_SUCCESS)
{
   sema = mmap(/* ... */);

   if (sema == MAP_FAILED)
   {
      status = EXIT_FAILURE;
   }
}

if (status == EXIT_SUCCESS)
{
   foo = malloc(sizeof(*foo));
   if (!foo)
   {
      status = EXIT_FAILURE;
   }
}

if (status == EXIT_SUCCESS)
{
   // TODO: do stuff with sema and foo
}

if (sema &amp;&amp; sema != MAP_FAILED)
   munmap(sema, /* ... */);
if (foo)
   free(foo);

return status;