How did Sarakani become a stream enterer despite having an alcohol drinking habit? I read SN 55.24 (quoted below) and it says Sarakani became a stream enterer despite having an alcohol drinking habit, because he undertook the training before he died.

What does the sutta really mean? Does it mean he gave up alcohol and undertook the training, then became a stream enterer?

The sutta isn't very clear on whether Sarakani gave up alcohol. Did he give it up? Or not?


  Now at that time Sarakāni the Sakyan had passed away. The Buddha
  declared that he was a stream-enterer, not liable to be reborn in the
  underworld, bound for awakening.
  
  At that, several Sakyans came together complaining, grumbling, and
  objecting, “It’s incredible, it’s amazing! Who can’t become a
  stream-enterer these days? For the Buddha even declared Sarakāni to be
  a stream-enterer after he passed away. Sarakāni was too weak for the
  training; he used to drink alcohol.”
Does it meant that he gave up alcohol and undertook the training, and became a stream enterer?

That's not how I read the translation, i.e. I'm not sure that is what's implied.

Perhaps I should start by mentioning that, whereas SN 55.24 says ...


  Sarakāni was too weak for the training; he used to drink alcohol.”
  Saraṇāni sakko sikkhādubbalyamāpādi, majjapānaṃ apāyī”ti.


... there's SN 55.25 which says ...


  Sarakāni didn’t fulfill the training.”
  Saraṇāni sakko sikkhāya aparipūrakārī ahosī”ti.




Anyway, near the start of SN 55.24 it says,


  Mahānāma, when a lay follower has for a long time gone for refuge to the Buddha, the teaching, and the Saṅgha, how could they go to the underworld? And if anyone should rightly be said to have for a long time gone for refuge to the Buddha, the teaching, and the Saṅgha, it’s Sarakāni the Sakyan


So that's one thing and maybe enough.

It isn't the same story but see also the Weaver's Daughter ...


  At the conclusion of the discourse that maiden was established in the fruit of stream-entry


... and there a factor (and something that may have in common with this) was her having lived with the Buddha's message for a long time.

The next paragraphs talks about immersion and so on -- variations on a theme (all including immersion as a kind of minimum). The same person (Mahānāma the Sakyan) asked a related question in AN 3.73.

It ends with -- or perhaps, "But it ends with" (though it might be better to understand it without "but", because "without but" is a description of the end-state i.e. having completed stream-entry):


  If these great sal trees could understand what was well said and poorly said, I’d declare them to be stream-enterers. Why can’t this apply to Sarakāni?


I get the impression that stream-entry depends on understanding the Dhamma when it's spoken by the Buddha -- there are many examples of that (at the end of SN 56.11 for a start, but also often at the end of many suttas with the Bhagava and a lay-person).

So that's another thing (maybe the same thing), and also enough.

Finally it says,


  Mahānāma, Sarakāni the Sakyan undertook the training at the time of his death.
  Saraṇāni, mahānāma, sakko maraṇakāle sikkhaṃ samādiyī”ti.


The translation says "training" but the Pali says saraṇa -- maybe "refuge".

I think that's saying he became a stream enterer when he died, before he died, as he was dying -- however long that took, whether it was a moment before (Last thought before death?), or whether the "time of dying" (maraṇakāla) was days or weeks or longer, months.

I think we're meant to believe it's possible for a person -- for almost anyone (see also Aṅgulimāla, "The Buddha had often warned not to judge people from appearances and their external behavior").

And the suttas have many examples of people attaining a higher "stage" of enlightenment as they're dying.

My opinion, if you'll forgive it, is that I may be disinclined to recommend a life of drunkenness -- that might be crazy, and perhaps not in a good way. That said, it's possible (and fortunate) that stream entry may occur towards the end of life (though arguably not a safe bet and compassionate and everything to wait until then).

The sutta isn't very clear on whether Sarakani gave up alcohol. Did he give it up?

Perhaps you give up a lot as you're dying.


  
  People, other than the wise, do not realize, "We in this world must all die," (and, not realizing it, continue their quarrels). The wise realize it and thereby their quarrels cease.